aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2012-09-28 22:46:33 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2012-09-28 22:46:33 +0200
commita3c12fb6c5b1cdd4fb84e0ac18fc8820f79cf7fd (patch)
tree7c6eaea671f52f75a8e592cf171c3e0313a5bf77
parenta9be1547b1b4459d64d92207da2a29e41fcb3ba2 (diff)
Fix: Cleanly open and close NS instance
-rw-r--r--src/gprs_bssgp_pcu.cpp9
-rw-r--r--src/sysmo_sock.cpp18
2 files changed, 19 insertions, 8 deletions
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index 4b0255e..7ec4ee8 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -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);
diff --git a/src/sysmo_sock.cpp b/src/sysmo_sock.cpp
index e3b9516..c456595 100644
--- a/src/sysmo_sock.cpp
+++ b/src/sysmo_sock.cpp
@@ -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;
}