From 098850d0a8bc671e8c06fc1b9b6d99f98d39cdd4 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 26 Aug 2016 19:31:16 +0200 Subject: server: Move to a write_queue for the conn socket We are only reading from the socket and never write but the osmo_tls code is integrated with it. We will never write and the queue size is set to 0. Simplify the read_cb. Change-Id: I32335b1f7b7ed06b92c6222516c185301ce13781 --- include/osmo-pcap/osmo_pcap_server.h | 3 ++- src/osmo_server_network.c | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h index a386a2a..fe4629e 100644 --- a/include/osmo-pcap/osmo_pcap_server.h +++ b/include/osmo-pcap/osmo_pcap_server.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -74,7 +75,7 @@ struct osmo_pcap_conn { struct in_addr remote_addr; /* Remote connection */ - struct osmo_fd rem_fd; + struct osmo_wqueue rem_wq; int local_fd; char *curr_filename; diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c index 22af2b4..8d662f6 100644 --- a/src/osmo_server_network.c +++ b/src/osmo_server_network.c @@ -129,10 +129,10 @@ void osmo_pcap_server_close_trace(struct osmo_pcap_conn *conn) static void close_connection(struct osmo_pcap_conn *conn) { - if (conn->rem_fd.fd >= 0) { - close(conn->rem_fd.fd); - conn->rem_fd.fd = -1; - osmo_fd_unregister(&conn->rem_fd); + if (conn->rem_wq.bfd.fd >= 0) { + close(conn->rem_wq.bfd.fd); + conn->rem_wq.bfd.fd = -1; + osmo_fd_unregister(&conn->rem_wq.bfd); } osmo_pcap_server_close_trace(conn); @@ -303,7 +303,9 @@ struct osmo_pcap_conn *osmo_pcap_server_find(struct osmo_pcap_server *server, conn->name = talloc_strdup(conn, name); - conn->rem_fd.fd = -1; + /* we never write */ + osmo_wqueue_init(&conn->rem_wq, 0); + conn->rem_wq.bfd.fd = -1; conn->local_fd = -1; conn->server = server; conn->data = (struct osmo_pcap_data *) &conn->buf[0]; @@ -387,7 +389,7 @@ static int read_cb_data(struct osmo_fd *fd, struct osmo_pcap_conn *conn) return 0; } -static int read_cb(struct osmo_fd *fd, unsigned int what) +static int read_cb(struct osmo_fd *fd) { struct osmo_pcap_conn *conn; @@ -413,19 +415,19 @@ static void new_connection(struct osmo_pcap_server *server, close_connection(client); memset(&client->file_hdr, 0, sizeof(client->file_hdr)); - client->rem_fd.fd = new_fd; - if (osmo_fd_register(&client->rem_fd) != 0) { + client->rem_wq.bfd.fd = new_fd; + if (osmo_fd_register(&client->rem_wq.bfd) != 0) { LOGP(DSERVER, LOGL_ERROR, "Failed to register fd.\n"); - client->rem_fd.fd = -1; + client->rem_wq.bfd.fd = -1; close(new_fd); return; } rate_ctr_inc(&client->ctrg->ctr[PEER_CTR_CONNECT]); - client->rem_fd.data = client; - client->rem_fd.when = BSC_FD_READ; - client->rem_fd.cb = read_cb; + client->rem_wq.bfd.data = client; + client->rem_wq.bfd.when = BSC_FD_READ; + client->rem_wq.read_cb = read_cb; client->state = STATE_INITIAL; client->pend = sizeof(*client->data); } -- cgit v1.2.3