diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-15 21:14:38 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-15 23:34:35 +0200 |
commit | cee5fb36dab5741c2f2a5b5952e734bac6621c8f (patch) | |
tree | 1bb067796b0cb2c6105e008a9b9dd55b2a2fa9ef /src | |
parent | ad2e9d637e27a6c51fa6f4ae8ec81075a6448c27 (diff) |
src: shorter stream function names
%s/_client_conn_/_cli_/g
%s/_server_conn_/_srv_/g
%s/_client_/cli/g
%s/server/srv/g
%s/RECONFIG/RECONF/g
%s/SERVER/SRV/g
%s/CLIENT/CLI/g
Diffstat (limited to 'src')
-rw-r--r-- | src/channel/abis_ipa_server.c | 220 | ||||
-rw-r--r-- | src/stream.c | 313 |
2 files changed, 263 insertions, 270 deletions
diff --git a/src/channel/abis_ipa_server.c b/src/channel/abis_ipa_server.c index bc6bacc..1038fc1 100644 --- a/src/channel/abis_ipa_server.c +++ b/src/channel/abis_ipa_server.c @@ -21,12 +21,12 @@ static void *abis_ipa_server_tall; -static int oml_accept_cb(struct osmo_stream_server_link *server, int fd); -static int rsl_accept_cb(struct osmo_stream_server_link *server, int fd); +static int oml_accept_cb(struct osmo_stream_srv_link *server, int fd); +static int rsl_accept_cb(struct osmo_stream_srv_link *server, int fd); struct chan_abis_ipa_server { - struct osmo_stream_server_link *oml; - struct osmo_stream_server_link *rsl; + struct osmo_stream_srv_link *oml; + struct osmo_stream_srv_link *rsl; struct llist_head bts_list; struct llist_head conn_list; @@ -40,55 +40,55 @@ struct ipa_unit { uint16_t bts_id; }; -struct ipa_conn { +struct ipa { struct llist_head head; struct ipa_unit *unit; struct osmo_chan *chan; - struct osmo_stream_server_conn *oml; - struct osmo_stream_server_conn *rsl; + struct osmo_stream_srv *oml; + struct osmo_stream_srv *rsl; }; static int chan_abis_ipa_server_create(struct osmo_chan *chan) { struct chan_abis_ipa_server *c = (struct chan_abis_ipa_server *)chan->data; - struct ipa_conn *ipa_conn; + struct ipa *ipa; /* dummy connection. */ - ipa_conn = talloc_zero(chan->ctx, struct ipa_conn); - if (ipa_conn == NULL) + ipa = talloc_zero(chan->ctx, struct ipa); + if (ipa == NULL) goto err; - ipa_conn->chan = chan; + ipa->chan = chan; - c->oml = osmo_stream_server_link_create(abis_ipa_server_tall); + c->oml = osmo_stream_srv_link_create(abis_ipa_server_tall); if (c->oml == NULL) goto err_oml; /* default address and port for OML. */ - osmo_stream_server_link_set_addr(c->oml, "0.0.0.0"); - osmo_stream_server_link_set_port(c->oml, IPA_TCP_PORT_OML); - osmo_stream_server_link_set_accept_cb(c->oml, oml_accept_cb); - osmo_stream_server_link_set_data(c->oml, ipa_conn); + osmo_stream_srv_link_set_addr(c->oml, "0.0.0.0"); + osmo_stream_srv_link_set_port(c->oml, IPA_TCP_PORT_OML); + osmo_stream_srv_link_set_accept_cb(c->oml, oml_accept_cb); + osmo_stream_srv_link_set_data(c->oml, ipa); - c->rsl = osmo_stream_server_link_create(abis_ipa_server_tall); + c->rsl = osmo_stream_srv_link_create(abis_ipa_server_tall); if (c->rsl == NULL) goto err_rsl; /* default address and port for RSL. */ - osmo_stream_server_link_set_addr(c->rsl, "0.0.0.0"); - osmo_stream_server_link_set_port(c->rsl, IPA_TCP_PORT_RSL); - osmo_stream_server_link_set_accept_cb(c->rsl, rsl_accept_cb); - osmo_stream_server_link_set_data(c->rsl, ipa_conn); + osmo_stream_srv_link_set_addr(c->rsl, "0.0.0.0"); + osmo_stream_srv_link_set_port(c->rsl, IPA_TCP_PORT_RSL); + osmo_stream_srv_link_set_accept_cb(c->rsl, rsl_accept_cb); + osmo_stream_srv_link_set_data(c->rsl, ipa); INIT_LLIST_HEAD(&c->bts_list); INIT_LLIST_HEAD(&c->conn_list); return 0; err_rsl: - osmo_stream_server_link_destroy(c->oml); + osmo_stream_srv_link_destroy(c->oml); err_oml: - talloc_free(ipa_conn); + talloc_free(ipa); err: return -1; } @@ -97,10 +97,10 @@ static void chan_abis_ipa_server_destroy(struct osmo_chan *chan) { struct chan_abis_ipa_server *c = (struct chan_abis_ipa_server *)chan->data; - struct ipa_conn *ipa_conn = - osmo_stream_server_link_get_data(c->oml); + struct ipa *ipa = + osmo_stream_srv_link_get_data(c->oml); - talloc_free(ipa_conn); + talloc_free(ipa); talloc_free(c->rsl); talloc_free(c->oml); } @@ -112,18 +112,18 @@ static int chan_abis_ipa_server_open(struct osmo_chan *chan) struct osmo_fd *ofd; int ret, on = 1; - if (osmo_stream_server_link_open(c->oml) < 0) + if (osmo_stream_srv_link_open(c->oml) < 0) goto err; - ofd = osmo_stream_server_link_get_ofd(c->oml); + ofd = osmo_stream_srv_link_get_ofd(c->oml); ret = setsockopt(ofd->fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); if (ret < 0) goto err_oml; - if (osmo_stream_server_link_open(c->rsl) < 0) + if (osmo_stream_srv_link_open(c->rsl) < 0) goto err_oml; - ofd = osmo_stream_server_link_get_ofd(c->rsl); + ofd = osmo_stream_srv_link_get_ofd(c->rsl); ret = setsockopt(ofd->fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); if (ret < 0) goto err_rsl; @@ -131,9 +131,9 @@ static int chan_abis_ipa_server_open(struct osmo_chan *chan) return 0; err_rsl: - osmo_stream_server_link_close(c->rsl); + osmo_stream_srv_link_close(c->rsl); err_oml: - osmo_stream_server_link_close(c->oml); + osmo_stream_srv_link_close(c->oml); err: return -1; } @@ -143,13 +143,13 @@ static void chan_abis_ipa_server_close(struct osmo_chan *chan) struct chan_abis_ipa_server *c = (struct chan_abis_ipa_server *)chan->data; - osmo_stream_server_link_close(c->oml); - osmo_stream_server_link_close(c->rsl); + osmo_stream_srv_link_close(c->oml); + osmo_stream_srv_link_close(c->rsl); } static int chan_abis_ipa_server_enqueue(struct osmo_chan *c, struct msgb *msg) { - osmo_stream_server_conn_send(msg->dst, msg); + osmo_stream_srv_send(msg->dst, msg); return 0; } @@ -159,7 +159,7 @@ osmo_chan_abis_ipa_server_set_oml_addr(struct osmo_chan *c, const char *addr) struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)&c->data; - osmo_stream_server_link_set_addr(s->oml, addr); + osmo_stream_srv_link_set_addr(s->oml, addr); } void @@ -168,7 +168,7 @@ osmo_chan_abis_ipa_server_set_oml_port(struct osmo_chan *c, uint16_t port) struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)&c->data; - osmo_stream_server_link_set_port(s->oml, port); + osmo_stream_srv_link_set_port(s->oml, port); } void @@ -177,7 +177,7 @@ osmo_chan_abis_ipa_server_set_rsl_addr(struct osmo_chan *c, const char *addr) struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)&c->data; - osmo_stream_server_link_set_addr(s->rsl, addr); + osmo_stream_srv_link_set_addr(s->rsl, addr); } void @@ -186,7 +186,7 @@ osmo_chan_abis_ipa_server_set_rsl_port(struct osmo_chan *c, uint16_t port) struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)&c->data; - osmo_stream_server_link_set_port(s->rsl, port); + osmo_stream_srv_link_set_port(s->rsl, port); } void @@ -199,23 +199,23 @@ osmo_chan_abis_ipa_server_set_cb_signalmsg(struct osmo_chan *c, s->signal_msg = signal_msg; } -static int oml_read_cb(struct osmo_stream_server_conn *conn); +static int oml_read_cb(struct osmo_stream_srv *conn); -static int oml_accept_cb(struct osmo_stream_server_link *server, int fd) +static int oml_accept_cb(struct osmo_stream_srv_link *server, int fd) { - struct osmo_stream_server_conn *conn; - struct ipa_conn *ipa_conn = osmo_stream_server_link_get_data(server); + struct osmo_stream_srv *conn; + struct ipa *ipa = osmo_stream_srv_link_get_data(server); struct osmo_fd *ofd; - conn = osmo_stream_server_conn_create(abis_ipa_server_tall, + conn = osmo_stream_srv_create(abis_ipa_server_tall, server, fd, - oml_read_cb, NULL, ipa_conn); + oml_read_cb, NULL, ipa); if (conn == NULL) { LOGP(DLINP, LOGL_ERROR, "error while creating connection\n"); return -1; } - ofd = osmo_stream_server_conn_get_ofd(conn); + ofd = osmo_stream_srv_get_ofd(conn); /* XXX: better use chan_abis_ipa_server_enqueue. */ ipaccess_send_id_req(ofd->fd); @@ -223,23 +223,23 @@ static int oml_accept_cb(struct osmo_stream_server_link *server, int fd) return 0; } -static int rsl_read_cb(struct osmo_stream_server_conn *conn); +static int rsl_read_cb(struct osmo_stream_srv *conn); -static int rsl_accept_cb(struct osmo_stream_server_link *server, int fd) +static int rsl_accept_cb(struct osmo_stream_srv_link *server, int fd) { - struct osmo_stream_server_conn *conn; - struct ipa_conn *ipa_conn = osmo_stream_server_link_get_data(server); + struct osmo_stream_srv *conn; + struct ipa *ipa = osmo_stream_srv_link_get_data(server); struct osmo_fd *ofd; - conn = osmo_stream_server_conn_create(abis_ipa_server_tall, + conn = osmo_stream_srv_create(abis_ipa_server_tall, server, fd, - rsl_read_cb, NULL, ipa_conn); + rsl_read_cb, NULL, ipa); if (conn == NULL) { LOGP(DLINP, LOGL_ERROR, "error while creating connection\n"); return -1; } - ofd = osmo_stream_server_conn_get_ofd(conn); + ofd = osmo_stream_srv_get_ofd(conn); /* XXX: better use chan_abis_ipa_server_enqueue. */ ipaccess_send_id_req(ofd->fd); @@ -281,70 +281,70 @@ osmo_chan_abis_ipa_unit_add(struct osmo_chan *c, return 0; } -static struct ipa_conn * -osmo_ipa_conn_alloc(struct ipa_unit *unit, struct osmo_chan *chan) +static struct ipa * +osmo_ipa_alloc(struct ipa_unit *unit, struct osmo_chan *chan) { - struct ipa_conn *ipa_conn; + struct ipa *ipa; - ipa_conn = talloc_zero(chan->ctx, struct ipa_conn); - if (ipa_conn == NULL) + ipa = talloc_zero(chan->ctx, struct ipa); + if (ipa == NULL) return NULL; - ipa_conn->unit = unit; - ipa_conn->chan = chan; + ipa->unit = unit; + ipa->chan = chan; - return ipa_conn; + return ipa; } -static struct ipa_conn * -osmo_ipa_conn_add(struct ipa_unit *unit, struct osmo_chan *chan) +static struct ipa * +osmo_ipa_add(struct ipa_unit *unit, struct osmo_chan *chan) { - struct ipa_conn *ipa_conn; + struct ipa *ipa; struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)chan->data; - ipa_conn = osmo_ipa_conn_alloc(unit, chan); - if (ipa_conn == NULL) + ipa = osmo_ipa_alloc(unit, chan); + if (ipa == NULL) return NULL; - llist_add(&ipa_conn->head, &s->conn_list); + llist_add(&ipa->head, &s->conn_list); - return ipa_conn; + return ipa; } -static struct ipa_conn * -osmo_ipa_conn_find(struct ipa_unit *unit, struct osmo_chan *chan) +static struct ipa * +osmo_ipa_find(struct ipa_unit *unit, struct osmo_chan *chan) { - struct ipa_conn *ipa_conn; + struct ipa *ipa; struct chan_abis_ipa_server *s = (struct chan_abis_ipa_server *)chan->data; - llist_for_each_entry(ipa_conn, &s->conn_list, head) { - if (ipa_conn->unit->site_id == unit->site_id && - ipa_conn->unit->bts_id == unit->bts_id) { - return ipa_conn; + llist_for_each_entry(ipa, &s->conn_list, head) { + if (ipa->unit->site_id == unit->site_id && + ipa->unit->bts_id == unit->bts_id) { + return ipa; } } return NULL; } static void -osmo_ipa_conn_put(struct ipa_conn *ipa_conn) +osmo_ipa_put(struct ipa *ipa) { - llist_del(&ipa_conn->head); - osmo_stream_server_conn_destroy(ipa_conn->oml); - osmo_stream_server_conn_destroy(ipa_conn->rsl); - talloc_free(ipa_conn); + llist_del(&ipa->head); + osmo_stream_srv_destroy(ipa->oml); + osmo_stream_srv_destroy(ipa->rsl); + talloc_free(ipa); } static int abis_ipa_server_rcvmsg(struct osmo_chan *c, - struct osmo_stream_server_conn *conn, + struct osmo_stream_srv *conn, struct msgb *msg, int type) { struct tlv_parsed tlvp; uint8_t msg_type = *(msg->l2h); - struct osmo_fd *ofd = osmo_stream_server_conn_get_ofd(conn); + struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn); char *unitid; int len, ret; @@ -354,7 +354,7 @@ abis_ipa_server_rcvmsg(struct osmo_chan *c, if (msg_type == IPAC_MSGT_ID_RESP) { struct ipa_unit *unit; - struct ipa_conn *ipa_conn; + struct ipa *ipa; struct ipaccess_unit unit_data; DEBUGP(DLMI, "ID_RESP\n"); @@ -399,35 +399,35 @@ abis_ipa_server_rcvmsg(struct osmo_chan *c, unit_data.site_id, unit_data.bts_id, unit_data.trx_id); - ipa_conn = osmo_ipa_conn_find(unit, c); - if (ipa_conn == NULL) { - ipa_conn = osmo_ipa_conn_add(unit, c); - if (ipa_conn == NULL) { + ipa = osmo_ipa_find(unit, c); + if (ipa == NULL) { + ipa = osmo_ipa_add(unit, c); + if (ipa == NULL) { LOGP(DLINP, LOGL_ERROR, "OOM\n"); return 0; } - osmo_stream_server_conn_set_data(conn, ipa_conn); + osmo_stream_srv_set_data(conn, ipa); } if (type == CHAN_SIGN_OML) { - if (ipa_conn->oml) { + if (ipa->oml) { /* link already exists, kill it. */ - osmo_stream_server_conn_destroy(ipa_conn->oml); + osmo_stream_srv_destroy(ipa->oml); return 0; } - ipa_conn->oml = conn; + ipa->oml = conn; } else if (type == CHAN_SIGN_RSL) { - if (!ipa_conn->oml) { + if (!ipa->oml) { /* no OML link? Restart from scratch. */ - osmo_ipa_conn_put(ipa_conn); + osmo_ipa_put(ipa); return 0; } - if (ipa_conn->rsl) { + if (ipa->rsl) { /* RSL link already exists, kill it. */ - osmo_stream_server_conn_destroy(ipa_conn->rsl); + osmo_stream_srv_destroy(ipa->rsl); return 0; } - ipa_conn->rsl = conn; + ipa->rsl = conn; } ret = 0; } else { @@ -438,12 +438,12 @@ err: return ret; } -static int read_cb(struct osmo_stream_server_conn *conn, int type) +static int read_cb(struct osmo_stream_srv *conn, int type) { int ret; struct msgb *msg; - struct osmo_fd *ofd = osmo_stream_server_conn_get_ofd(conn); - struct ipa_conn *ipa_conn = osmo_stream_server_conn_get_data(conn); + struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn); + struct ipa *ipa = osmo_stream_srv_get_data(conn); struct chan_abis_ipa_server *s; struct ipa_head *hh; @@ -459,27 +459,27 @@ static int read_cb(struct osmo_stream_server_conn *conn, int type) LOGP(DLINP, LOGL_ERROR, "cannot receive message\n"); msgb_free(msg); /* not the dummy connection, release it. */ - if (ipa_conn->unit != NULL) - osmo_ipa_conn_put(ipa_conn); + if (ipa->unit != NULL) + osmo_ipa_put(ipa); return 0; } else if (ret == 0) { /* link has vanished, dead socket. */ LOGP(DLINP, LOGL_ERROR, "closed connection\n"); msgb_free(msg); - if (ipa_conn->unit != NULL) - osmo_ipa_conn_put(ipa_conn); + if (ipa->unit != NULL) + osmo_ipa_put(ipa); return 0; } hh = (struct ipa_head *) msg->data; if (hh->proto == IPAC_PROTO_IPACCESS) { - abis_ipa_server_rcvmsg(ipa_conn->chan, conn, msg, type); + abis_ipa_server_rcvmsg(ipa->chan, conn, msg, type); msgb_free(msg); return -EIO; } - ipa_conn = osmo_stream_server_conn_get_data(conn); - if (ipa_conn == NULL) { + ipa = osmo_stream_srv_get_data(conn); + if (ipa == NULL) { LOGP(DLINP, LOGL_ERROR, "no matching signalling link\n"); msgb_free(msg); return -EIO; @@ -488,20 +488,20 @@ static int read_cb(struct osmo_stream_server_conn *conn, int type) LOGP(DLINP, LOGL_ERROR, "wrong protocol\n"); return -EIO; } - msg->dst = ipa_conn; + msg->dst = ipa; - s = (struct chan_abis_ipa_server *)ipa_conn->chan->data; + s = (struct chan_abis_ipa_server *)ipa->chan->data; s->signal_msg(msg, type); return 0; } -static int oml_read_cb(struct osmo_stream_server_conn *conn) +static int oml_read_cb(struct osmo_stream_srv *conn) { return read_cb(conn, CHAN_SIGN_OML); } -static int rsl_read_cb(struct osmo_stream_server_conn *conn) +static int rsl_read_cb(struct osmo_stream_srv *conn) { return read_cb(conn, CHAN_SIGN_RSL); } diff --git a/src/stream.c b/src/stream.c index b32f9b5..c72de3c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -23,61 +23,61 @@ * Client side. */ -enum osmo_stream_client_conn_state { - STREAM_CLIENT_LINK_STATE_NONE = 0, - STREAM_CLIENT_LINK_STATE_CONNECTING = 1, - STREAM_CLIENT_LINK_STATE_CONNECTED = 2, - STREAM_CLIENT_LINK_STATE_MAX +enum osmo_stream_cli_state { + STREAM_CLI_STATE_NONE = 0, + STREAM_CLI_STATE_CONNECTING = 1, + STREAM_CLI_STATE_CONNECTED = 2, + STREAM_CLI_STATE_MAX }; -#define OSMO_STREAM_CLIENT_F_RECONFIG (1 << 0) +#define OSMO_STREAM_CLI_F_RECONF (1 << 0) -struct osmo_stream_client_conn { +struct osmo_stream_cli { struct osmo_fd ofd; struct llist_head tx_queue; struct osmo_timer_list timer; - enum osmo_stream_client_conn_state state; + enum osmo_stream_cli_state state; const char *addr; uint16_t port; - int (*connect_cb)(struct osmo_stream_client_conn *link); - int (*read_cb)(struct osmo_stream_client_conn *link); - int (*write_cb)(struct osmo_stream_client_conn *link); + int (*connect_cb)(struct osmo_stream_cli *srv); + int (*read_cb)(struct osmo_stream_cli *srv); + int (*write_cb)(struct osmo_stream_cli *srv); void *data; int flags; int reconnect_timeout; }; -void osmo_stream_client_conn_close(struct osmo_stream_client_conn *link); +void osmo_stream_cli_close(struct osmo_stream_cli *cli); -static void osmo_stream_client_reconnect(struct osmo_stream_client_conn *link) +static void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli) { - if (link->reconnect_timeout < 0) { + if (cli->reconnect_timeout < 0) { LOGP(DLINP, LOGL_DEBUG, "not reconnecting, disabled.\n"); return; } LOGP(DLINP, LOGL_DEBUG, "connection closed\n"); - osmo_stream_client_conn_close(link); + osmo_stream_cli_close(cli); LOGP(DLINP, LOGL_DEBUG, "retrying in %d seconds...\n", - link->reconnect_timeout); - osmo_timer_schedule(&link->timer, link->reconnect_timeout, 0); - link->state = STREAM_CLIENT_LINK_STATE_CONNECTING; + cli->reconnect_timeout); + osmo_timer_schedule(&cli->timer, cli->reconnect_timeout, 0); + cli->state = STREAM_CLI_STATE_CONNECTING; } -void osmo_stream_client_conn_close(struct osmo_stream_client_conn *link) +void osmo_stream_cli_close(struct osmo_stream_cli *cli) { - osmo_fd_unregister(&link->ofd); - close(link->ofd.fd); + osmo_fd_unregister(&cli->ofd); + close(cli->ofd.fd); } -static void osmo_stream_client_read(struct osmo_stream_client_conn *link) +static void osmo_stream_cli_read(struct osmo_stream_cli *cli) { LOGP(DLINP, LOGL_DEBUG, "message received\n"); - if (link->read_cb) - link->read_cb(link); + if (cli->read_cb) + cli->read_cb(cli); } -static int osmo_stream_client_write(struct osmo_stream_client_conn *link) +static int osmo_stream_cli_write(struct osmo_stream_cli *cli) { struct msgb *msg; struct llist_head *lh; @@ -85,23 +85,23 @@ static int osmo_stream_client_write(struct osmo_stream_client_conn *link) LOGP(DLINP, LOGL_DEBUG, "sending data\n"); - if (llist_empty(&link->tx_queue)) { - link->ofd.when &= ~BSC_FD_WRITE; + if (llist_empty(&cli->tx_queue)) { + cli->ofd.when &= ~BSC_FD_WRITE; return 0; } - lh = link->tx_queue.next; + lh = cli->tx_queue.next; llist_del(lh); msg = llist_entry(lh, struct msgb, list); - if (link->state == STREAM_CLIENT_LINK_STATE_CONNECTING) { + if (cli->state == STREAM_CLI_STATE_CONNECTING) { LOGP(DLINP, LOGL_ERROR, "not connected, dropping data!\n"); return 0; } - ret = send(link->ofd.fd, msg->data, msg->len, 0); + ret = send(cli->ofd.fd, msg->data, msg->len, 0); if (ret < 0) { if (errno == EPIPE || errno == ENOTCONN) { - osmo_stream_client_reconnect(link); + osmo_stream_cli_reconnect(cli); } LOGP(DLINP, LOGL_ERROR, "error to send\n"); } @@ -109,33 +109,33 @@ static int osmo_stream_client_write(struct osmo_stream_client_conn *link) return 0; } -static int osmo_stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what) +static int osmo_stream_cli_fd_cb(struct osmo_fd *ofd, unsigned int what) { - struct osmo_stream_client_conn *link = ofd->data; + struct osmo_stream_cli *cli = ofd->data; int error, ret; socklen_t len = sizeof(error); - switch(link->state) { - case STREAM_CLIENT_LINK_STATE_CONNECTING: + switch(cli->state) { + case STREAM_CLI_STATE_CONNECTING: ret = getsockopt(ofd->fd, SOL_SOCKET, SO_ERROR, &error, &len); if (ret >= 0 && error > 0) { - osmo_stream_client_reconnect(link); + osmo_stream_cli_reconnect(cli); return 0; } ofd->when &= ~BSC_FD_WRITE; LOGP(DLINP, LOGL_DEBUG, "connection done.\n"); - link->state = STREAM_CLIENT_LINK_STATE_CONNECTED; - if (link->connect_cb) - link->connect_cb(link); + cli->state = STREAM_CLI_STATE_CONNECTED; + if (cli->connect_cb) + cli->connect_cb(cli); break; - case STREAM_CLIENT_LINK_STATE_CONNECTED: + case STREAM_CLI_STATE_CONNECTED: if (what & BSC_FD_READ) { LOGP(DLINP, LOGL_DEBUG, "connected read\n"); - osmo_stream_client_read(link); + osmo_stream_cli_read(cli); } if (what & BSC_FD_WRITE) { LOGP(DLINP, LOGL_DEBUG, "connected write\n"); - osmo_stream_client_write(link); + osmo_stream_cli_write(cli); } break; default: @@ -144,156 +144,151 @@ static int osmo_stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what) return 0; } -static void link_timer_cb(void *data); +static void cli_timer_cb(void *data); -struct osmo_stream_client_conn *osmo_stream_client_conn_create(void *ctx) +struct osmo_stream_cli *osmo_stream_cli_create(void *ctx) { - struct osmo_stream_client_conn *link; + struct osmo_stream_cli *cli; - link = talloc_zero(ctx, struct osmo_stream_client_conn); - if (!link) + cli = talloc_zero(ctx, struct osmo_stream_cli); + if (!cli) return NULL; - link->ofd.fd = -1; - link->ofd.when |= BSC_FD_READ | BSC_FD_WRITE; - link->ofd.priv_nr = 0; /* XXX */ - link->ofd.cb = osmo_stream_client_fd_cb; - link->ofd.data = link; - link->state = STREAM_CLIENT_LINK_STATE_CONNECTING; - link->timer.cb = link_timer_cb; - link->timer.data = link; - link->reconnect_timeout = 5; /* default is 5 seconds. */ - INIT_LLIST_HEAD(&link->tx_queue); + cli->ofd.fd = -1; + cli->ofd.when |= BSC_FD_READ | BSC_FD_WRITE; + cli->ofd.priv_nr = 0; /* XXX */ + cli->ofd.cb = osmo_stream_cli_fd_cb; + cli->ofd.data = cli; + cli->state = STREAM_CLI_STATE_CONNECTING; + cli->timer.cb = cli_timer_cb; + cli->timer.data = link; + cli->reconnect_timeout = 5; /* default is 5 seconds. */ + INIT_LLIST_HEAD(&cli->tx_queue); - return link; + return cli; } void -osmo_stream_client_conn_set_addr(struct osmo_stream_client_conn *link, - const char *addr) +osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr) { - link->addr = talloc_strdup(link, addr); - link->flags |= OSMO_STREAM_CLIENT_F_RECONFIG; + cli->addr = talloc_strdup(cli, addr); + cli->flags |= OSMO_STREAM_CLI_F_RECONF; } void -osmo_stream_client_conn_set_port(struct osmo_stream_client_conn *link, - uint16_t port) +osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port) { - link->port = port; - link->flags |= OSMO_STREAM_CLIENT_F_RECONFIG; + cli->port = port; + cli->flags |= OSMO_STREAM_CLI_F_RECONF; } -void osmo_stream_client_conn_set_reconnect_timeout( - struct osmo_stream_client_conn *link, int timeout) +void +osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout) { - link->reconnect_timeout = timeout; + cli->reconnect_timeout = timeout; } void -osmo_stream_client_conn_set_data(struct osmo_stream_client_conn *link, - void *data) +osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data) { - link->data = data; + cli->data = data; } -void *osmo_stream_client_conn_get_data(struct osmo_stream_client_conn *link) +void *osmo_stream_cli_get_data(struct osmo_stream_cli *cli) { - return link->data; + return cli->data; } struct osmo_fd * -osmo_stream_client_conn_get_ofd(struct osmo_stream_client_conn *link) +osmo_stream_cli_get_ofd(struct osmo_stream_cli *cli) { - return &link->ofd; + return &cli->ofd; } void -osmo_stream_client_conn_set_connect_cb(struct osmo_stream_client_conn *link, - int (*connect_cb)(struct osmo_stream_client_conn *link)) +osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, + int (*connect_cb)(struct osmo_stream_cli *cli)) { - link->connect_cb = connect_cb; + cli->connect_cb = connect_cb; } void -osmo_stream_client_conn_set_read_cb(struct osmo_stream_client_conn *link, - int (*read_cb)(struct osmo_stream_client_conn *link)) +osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, + int (*read_cb)(struct osmo_stream_cli *cli)) { - link->read_cb = read_cb; + cli->read_cb = read_cb; } -void osmo_stream_client_conn_destroy(struct osmo_stream_client_conn *link) +void osmo_stream_cli_destroy(struct osmo_stream_cli *cli) { talloc_free(link); } -int osmo_stream_client_conn_open(struct osmo_stream_client_conn *link) +int osmo_stream_cli_open(struct osmo_stream_cli *cli) { int ret; /* we are reconfiguring this socket, close existing first. */ - if ((link->flags & OSMO_STREAM_CLIENT_F_RECONFIG) && link->ofd.fd >= 0) - osmo_stream_client_conn_close(link); + if ((cli->flags & OSMO_STREAM_CLI_F_RECONF) && cli->ofd.fd >= 0) + osmo_stream_cli_close(cli); - link->flags &= ~OSMO_STREAM_CLIENT_F_RECONFIG; + cli->flags &= ~OSMO_STREAM_CLI_F_RECONF; ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP, - link->addr, link->port, + cli->addr, cli->port, OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_NONBLOCK); if (ret < 0) { if (errno != EINPROGRESS) return ret; } - link->ofd.fd = ret; - if (osmo_fd_register(&link->ofd) < 0) { + cli->ofd.fd = ret; + if (osmo_fd_register(&cli->ofd) < 0) { close(ret); return -EIO; } return 0; } -static void link_timer_cb(void *data) +static void cli_timer_cb(void *data) { - struct osmo_stream_client_conn *link = data; + struct osmo_stream_cli *cli = data; LOGP(DLINP, LOGL_DEBUG, "reconnecting.\n"); - switch(link->state) { - case STREAM_CLIENT_LINK_STATE_CONNECTING: - osmo_stream_client_conn_open(link); + switch(cli->state) { + case STREAM_CLI_STATE_CONNECTING: + osmo_stream_cli_open(cli); break; default: break; } } -void osmo_stream_client_conn_send(struct osmo_stream_client_conn *link, - struct msgb *msg) +void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg) { - msgb_enqueue(&link->tx_queue, msg); - link->ofd.when |= BSC_FD_WRITE; + msgb_enqueue(&cli->tx_queue, msg); + cli->ofd.when |= BSC_FD_WRITE; } -int osmo_stream_client_conn_recv(struct osmo_stream_client_conn *link, - struct msgb *msg) +int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg) { int ret; - ret = recv(link->ofd.fd, msg->data, msg->data_len, 0); + ret = recv(cli->ofd.fd, msg->data, msg->data_len, 0); if (ret < 0) { if (errno == EPIPE || errno == ECONNRESET) { LOGP(DLINP, LOGL_ERROR, - "lost connection with server\n"); + "lost connection with srv\n"); } - osmo_stream_client_reconnect(link); + osmo_stream_cli_reconnect(cli); return ret; } else if (ret == 0) { - LOGP(DLINP, LOGL_ERROR, "connection closed with server\n"); - osmo_stream_client_reconnect(link); + LOGP(DLINP, LOGL_ERROR, "connection closed with srv\n"); + osmo_stream_cli_reconnect(cli); return ret; } msgb_put(msg, ret); - LOGP(DLINP, LOGL_DEBUG, "received %d bytes from server\n", ret); + LOGP(DLINP, LOGL_DEBUG, "received %d bytes from srv\n", ret); return ret; } @@ -301,23 +296,23 @@ int osmo_stream_client_conn_recv(struct osmo_stream_client_conn *link, * Server side. */ -#define OSMO_STREAM_SERVER_F_RECONFIG (1 << 0) +#define OSMO_STREAM_SRV_F_RECONF (1 << 0) -struct osmo_stream_server_link { +struct osmo_stream_srv_link { struct osmo_fd ofd; const char *addr; uint16_t port; - int (*accept_cb)(struct osmo_stream_server_link *link, int fd); + int (*accept_cb)(struct osmo_stream_srv_link *srv, int fd); void *data; int flags; }; -static int osmo_stream_server_fd_cb(struct osmo_fd *ofd, unsigned int what) +static int osmo_stream_srv_fd_cb(struct osmo_fd *ofd, unsigned int what) { int ret; struct sockaddr_in sa; socklen_t sa_len = sizeof(sa); - struct osmo_stream_server_link *link = ofd->data; + struct osmo_stream_srv_link *link = ofd->data; ret = accept(ofd->fd, (struct sockaddr *)&sa, &sa_len); if (ret < 0) { @@ -334,75 +329,75 @@ static int osmo_stream_server_fd_cb(struct osmo_fd *ofd, unsigned int what) return 0; } -struct osmo_stream_server_link *osmo_stream_server_link_create(void *ctx) +struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) { - struct osmo_stream_server_link *link; + struct osmo_stream_srv_link *link; - link = talloc_zero(ctx, struct osmo_stream_server_link); + link = talloc_zero(ctx, struct osmo_stream_srv_link); if (!link) return NULL; link->ofd.fd = -1; link->ofd.when |= BSC_FD_READ | BSC_FD_WRITE; - link->ofd.cb = osmo_stream_server_fd_cb; + link->ofd.cb = osmo_stream_srv_fd_cb; link->ofd.data = link; return link; } -void osmo_stream_server_link_set_addr(struct osmo_stream_server_link *link, +void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr) { link->addr = talloc_strdup(link, addr); - link->flags |= OSMO_STREAM_SERVER_F_RECONFIG; + link->flags |= OSMO_STREAM_SRV_F_RECONF; } -void osmo_stream_server_link_set_port(struct osmo_stream_server_link *link, +void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port) { link->port = port; - link->flags |= OSMO_STREAM_SERVER_F_RECONFIG; + link->flags |= OSMO_STREAM_SRV_F_RECONF; } void -osmo_stream_server_link_set_data(struct osmo_stream_server_link *link, +osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data) { link->data = data; } -void *osmo_stream_server_link_get_data(struct osmo_stream_server_link *link) +void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link) { return link->data; } struct osmo_fd * -osmo_stream_server_link_get_ofd(struct osmo_stream_server_link *link) +osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link) { return &link->ofd; } -void osmo_stream_server_link_set_accept_cb(struct osmo_stream_server_link *link, - int (*accept_cb)(struct osmo_stream_server_link *link, int fd)) +void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, + int (*accept_cb)(struct osmo_stream_srv_link *link, int fd)) { link->accept_cb = accept_cb; } -void osmo_stream_server_link_destroy(struct osmo_stream_server_link *link) +void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link) { talloc_free(link); } -int osmo_stream_server_link_open(struct osmo_stream_server_link *link) +int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) { int ret; /* we are reconfiguring this socket, close existing first. */ - if ((link->flags & OSMO_STREAM_SERVER_F_RECONFIG) && link->ofd.fd >= 0) - osmo_stream_server_link_close(link); + if ((link->flags & OSMO_STREAM_SRV_F_RECONF) && link->ofd.fd >= 0) + osmo_stream_srv_link_close(link); - link->flags &= ~OSMO_STREAM_SERVER_F_RECONFIG; + link->flags &= ~OSMO_STREAM_SRV_F_RECONF; ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP, link->addr, link->port, OSMO_SOCK_F_BIND); @@ -417,22 +412,22 @@ int osmo_stream_server_link_open(struct osmo_stream_server_link *link) return 0; } -void osmo_stream_server_link_close(struct osmo_stream_server_link *link) +void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link) { osmo_fd_unregister(&link->ofd); close(link->ofd.fd); } -struct osmo_stream_server_conn { - struct osmo_stream_server_link *server; +struct osmo_stream_srv { + struct osmo_stream_srv_link *srv; struct osmo_fd ofd; struct llist_head tx_queue; - int (*closed_cb)(struct osmo_stream_server_conn *peer); - int (*cb)(struct osmo_stream_server_conn *peer); + int (*closed_cb)(struct osmo_stream_srv *peer); + int (*cb)(struct osmo_stream_srv *peer); void *data; }; -static void osmo_stream_server_conn_read(struct osmo_stream_server_conn *conn) +static void osmo_stream_srv_read(struct osmo_stream_srv *conn) { LOGP(DLINP, LOGL_DEBUG, "message received\n"); @@ -442,7 +437,7 @@ static void osmo_stream_server_conn_read(struct osmo_stream_server_conn *conn) return; } -static void osmo_stream_server_conn_write(struct osmo_stream_server_conn *conn) +static void osmo_stream_srv_write(struct osmo_stream_srv *conn) { struct msgb *msg; struct llist_head *lh; @@ -465,37 +460,37 @@ static void osmo_stream_server_conn_write(struct osmo_stream_server_conn *conn) msgb_free(msg); } -static int osmo_stream_server_conn_cb(struct osmo_fd *ofd, unsigned int what) +static int osmo_stream_srv_cb(struct osmo_fd *ofd, unsigned int what) { - struct osmo_stream_server_conn *conn = ofd->data; + struct osmo_stream_srv *conn = ofd->data; LOGP(DLINP, LOGL_DEBUG, "connected read/write\n"); if (what & BSC_FD_READ) - osmo_stream_server_conn_read(conn); + osmo_stream_srv_read(conn); if (what & BSC_FD_WRITE) - osmo_stream_server_conn_write(conn); + osmo_stream_srv_write(conn); return 0; } -struct osmo_stream_server_conn * -osmo_stream_server_conn_create(void *ctx, struct osmo_stream_server_link *link, +struct osmo_stream_srv * +osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link, int fd, - int (*cb)(struct osmo_stream_server_conn *conn), - int (*closed_cb)(struct osmo_stream_server_conn *conn), void *data) + int (*cb)(struct osmo_stream_srv *conn), + int (*closed_cb)(struct osmo_stream_srv *conn), void *data) { - struct osmo_stream_server_conn *conn; + struct osmo_stream_srv *conn; - conn = talloc_zero(ctx, struct osmo_stream_server_conn); + conn = talloc_zero(ctx, struct osmo_stream_srv); if (conn == NULL) { - LOGP(DLINP, LOGL_ERROR, "cannot allocate new peer in server, " + LOGP(DLINP, LOGL_ERROR, "cannot allocate new peer in srv, " "reason=`%s'\n", strerror(errno)); return NULL; } - conn->server = link; + conn->srv = link; conn->ofd.fd = fd; conn->ofd.data = conn; - conn->ofd.cb = osmo_stream_server_conn_cb; + conn->ofd.cb = osmo_stream_srv_cb; conn->ofd.when = BSC_FD_READ; conn->cb = cb; conn->closed_cb = closed_cb; @@ -511,24 +506,24 @@ osmo_stream_server_conn_create(void *ctx, struct osmo_stream_server_link *link, } void -osmo_stream_server_conn_set_data(struct osmo_stream_server_conn *conn, +osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data) { conn->data = data; } -void *osmo_stream_server_conn_get_data(struct osmo_stream_server_conn *link) +void *osmo_stream_srv_get_data(struct osmo_stream_srv *link) { return link->data; } struct osmo_fd * -osmo_stream_server_conn_get_ofd(struct osmo_stream_server_conn *link) +osmo_stream_srv_get_ofd(struct osmo_stream_srv *link) { return &link->ofd; } -void osmo_stream_server_conn_destroy(struct osmo_stream_server_conn *conn) +void osmo_stream_srv_destroy(struct osmo_stream_srv *conn) { close(conn->ofd.fd); osmo_fd_unregister(&conn->ofd); @@ -537,15 +532,13 @@ void osmo_stream_server_conn_destroy(struct osmo_stream_server_conn *conn) talloc_free(conn); } -void osmo_stream_server_conn_send(struct osmo_stream_server_conn *conn, - struct msgb *msg) +void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg) { msgb_enqueue(&conn->tx_queue, msg); conn->ofd.when |= BSC_FD_WRITE; } -int osmo_stream_server_conn_recv(struct osmo_stream_server_conn *conn, - struct msgb *msg) +int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg) { int ret; @@ -553,11 +546,11 @@ int osmo_stream_server_conn_recv(struct osmo_stream_server_conn *conn, if (ret < 0) { if (errno == EPIPE || errno == ECONNRESET) { LOGP(DLINP, LOGL_ERROR, - "lost connection with server\n"); + "lost connection with srv\n"); } return ret; } else if (ret == 0) { - LOGP(DLINP, LOGL_ERROR, "connection closed with server\n"); + LOGP(DLINP, LOGL_ERROR, "connection closed with srv\n"); return ret; } msgb_put(msg, ret); |