Fix: Cleanly open and close NS instance

This commit is contained in:
Andreas Eversberg 2012-09-28 22:46:33 +02:00
parent a9be1547b1
commit a3c12fb6c5
2 changed files with 19 additions and 8 deletions

View File

@ -530,6 +530,7 @@ int gprs_bssgp_create(uint32_t sgsn_ip, uint16_t sgsn_port, uint16_t nsei,
uint16_t rac, uint16_t cell_id)
{
struct sockaddr_in dest;
int rc;
mcc = ((mcc & 0xf00) >> 8) * 100 + ((mcc & 0x0f0) >> 4) * 10 + (mcc & 0x00f);
mnc = ((mnc & 0xf00) >> 8) * 100 + ((mnc & 0x0f0) >> 4) * 10 + (mnc & 0x00f);
@ -543,7 +544,13 @@ int gprs_bssgp_create(uint32_t sgsn_ip, uint16_t sgsn_port, uint16_t nsei,
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
return -EINVAL;
}
gprs_ns_nsip_listen(bssgp_nsi);
rc = gprs_ns_nsip_listen(bssgp_nsi);
if (rc < 0) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n");
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
return -EINVAL;
}
dest.sin_family = AF_INET;
dest.sin_port = htons(sgsn_port);

View File

@ -73,14 +73,15 @@ int pcu_sock_send(struct msgb *msg)
return 0;
}
static void pcu_sock_close(struct pcu_sock_state *state)
static void pcu_sock_close(struct pcu_sock_state *state, int lost)
{
struct osmo_fd *bfd = &state->conn_bfd;
struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
struct gprs_rlcmac_tbf *tbf;
uint8_t trx, ts, tfi;
LOGP(DL1IF, LOGL_NOTICE, "PCU socket has LOST connection\n");
LOGP(DL1IF, LOGL_NOTICE, "PCU socket has %s connection\n",
(lost) ? "LOST" : "closed");
close(bfd->fd);
bfd->fd = -1;
@ -108,8 +109,10 @@ static void pcu_sock_close(struct pcu_sock_state *state)
gprs_bssgp_destroy();
state->timer.cb = pcu_sock_timeout;
osmo_timer_schedule(&state->timer, 5, 0);
if (lost) {
state->timer.cb = pcu_sock_timeout;
osmo_timer_schedule(&state->timer, 5, 0);
}
}
static int pcu_sock_read(struct osmo_fd *bfd)
@ -145,7 +148,7 @@ static int pcu_sock_read(struct osmo_fd *bfd)
close:
msgb_free(msg);
pcu_sock_close(state);
pcu_sock_close(state, 1);
return -1;
}
@ -192,7 +195,7 @@ dontsend:
return 0;
close:
pcu_sock_close(state);
pcu_sock_close(state, 1);
return -1;
}
@ -256,6 +259,7 @@ int pcu_l1if_open(void)
if (rc != 0) {
LOGP(DL1IF, LOGL_ERROR, "Failed to Connect the PCU-SYSMO "
"socket, delaying... '%s'\n", local.sun_path);
pcu_sock_state = state;
close(bfd->fd);
bfd->fd = -1;
state->timer.cb = pcu_sock_timeout;
@ -295,7 +299,7 @@ void pcu_l1if_close(void)
bfd = &state->conn_bfd;
if (bfd->fd > 0)
pcu_sock_close(state);
pcu_sock_close(state, 0);
talloc_free(state);
pcu_sock_state = NULL;
}