aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-10-19 13:06:44 +0200
committerHarald Welte <laforge@osmocom.org>2020-10-19 13:06:44 +0200
commita9600141b82ad3f1640da0b3ef06107400379560 (patch)
treec168baece13ac8206431174e3e8884399f93ff23
parent20c6ba5a9e55f21ef1c9e70b96cf12bd11800182 (diff)
Use osmo_fd_setup() whenever applicableHEADmaster
-rw-r--r--src/osmo_client_core.c5
-rw-r--r--src/osmo_client_network.c11
-rw-r--r--src/osmo_tls.c8
3 files changed, 7 insertions, 17 deletions
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index c49bc1b..025e3a4 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -305,10 +305,7 @@ int osmo_client_capture(struct osmo_pcap_client *client, const char *device)
return 3;
}
- client->fd.fd = fd;
- client->fd.when = OSMO_FD_READ;
- client->fd.cb = pcap_read_cb;
- client->fd.data = client;
+ osmo_fd_setup(&client->fd, fd, OSMO_FD_READ, pcap_read_cb, client, 0);
if (osmo_fd_register(&client->fd) != 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to register the fd.\n");
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index c89847d..32d450f 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -267,6 +267,7 @@ void osmo_client_connect(struct osmo_pcap_client_conn *conn)
int rc;
uint16_t srv_port;
int sock_type, sock_proto;
+ unsigned int when;
osmo_client_disconnect(conn);
@@ -279,18 +280,20 @@ void osmo_client_connect(struct osmo_pcap_client_conn *conn)
srv_port = conn->srv_port;
sock_type = SOCK_STREAM;
sock_proto = IPPROTO_TCP;
+ when = OSMO_FD_READ | OSMO_FD_WRITE;
break;
case PROTOCOL_IPIP:
srv_port = 0;
sock_type = SOCK_RAW;
sock_proto = IPPROTO_IPIP;
- conn->wqueue.bfd.when = OSMO_FD_WRITE;
+ when = OSMO_FD_WRITE;
break;
default:
OSMO_ASSERT(0);
break;
}
+ osmo_fd_setup(&conn->wqueue.bfd, -1, when, conn_cb, conn, 0);
rc = osmo_sock_init2_ofd(&conn->wqueue.bfd, AF_INET, sock_type, sock_proto,
conn->source_ip, 0, conn->srv_ip, srv_port,
OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT | OSMO_SOCK_F_NONBLOCK);
@@ -303,12 +306,6 @@ void osmo_client_connect(struct osmo_pcap_client_conn *conn)
}
rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_CONNECT]);
- conn->wqueue.bfd.cb = conn_cb;
- conn->wqueue.bfd.data = conn;
- if (conn->protocol == PROTOCOL_IPIP)
- conn->wqueue.bfd.when = OSMO_FD_WRITE;
- else
- conn->wqueue.bfd.when = OSMO_FD_READ | OSMO_FD_WRITE;
}
void osmo_client_reconnect(struct osmo_pcap_client_conn *conn)
diff --git a/src/osmo_tls.c b/src/osmo_tls.c
index 56fedbb..f1671e9 100644
--- a/src/osmo_tls.c
+++ b/src/osmo_tls.c
@@ -435,9 +435,7 @@ bool osmo_tls_init_server_session(struct osmo_pcap_conn *conn,
gnutls_transport_set_int(sess->session, wq->bfd.fd);
gnutls_handshake_set_timeout(sess->session,
GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
- wq->bfd.cb = osmo_tls_client_bfd_cb;
- wq->bfd.data = sess;
- wq->bfd.when = OSMO_FD_READ | OSMO_FD_WRITE;
+ osmo_fd_setup(&wq->bfd, wq->bfd.fd, OSMO_FD_READ | OSMO_FD_WRITE, osmo_tls_client_bfd_cb, sess, 0);
sess->need_handshake = true;
sess->wqueue = wq;
return true;
@@ -531,9 +529,7 @@ bool osmo_tls_init_client_session(struct osmo_pcap_client_conn *client)
gnutls_transport_set_int(sess->session, wq->bfd.fd);
gnutls_handshake_set_timeout(sess->session,
GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
- wq->bfd.cb = osmo_tls_client_bfd_cb;
- wq->bfd.data = sess;
- wq->bfd.when = OSMO_FD_READ | OSMO_FD_WRITE;
+ osmo_fd_setup(&wq->bfd, wq->bfd.fd, OSMO_FD_READ | OSMO_FD_WRITE, osmo_tls_client_bfd_cb, sess, 0);
sess->need_handshake = true;
sess->wqueue = wq;
return true;