summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-10-18 23:34:46 +0200
committerHarald Welte <laforge@osmocom.org>2020-10-18 23:34:46 +0200
commitde31aa3af7304173809862321146595a08177981 (patch)
tree2aca769cc80db7dd4ce89361f542cb67a6dd657b
parent508d8523c042fc766d2eda61ac47b253660e9c5a (diff)
Use osmo_fd_setup() whenever applicable.
-rw-r--r--src/host/layer23/src/common/gps.c21
-rw-r--r--src/host/layer23/src/mobile/mncc_sock.c6
-rw-r--r--src/host/osmocon/osmocon.c15
-rw-r--r--src/host/trxcon/l1ctl_link.c13
-rw-r--r--src/host/virt_phy/src/l1ctl_sock.c9
-rw-r--r--src/host/virt_phy/src/shared/osmo_mcast_sock.c4
6 files changed, 22 insertions, 46 deletions
diff --git a/src/host/layer23/src/common/gps.c b/src/host/layer23/src/common/gps.c
index ef907d18..5225fe0e 100644
--- a/src/host/layer23/src/common/gps.c
+++ b/src/host/layer23/src/common/gps.c
@@ -137,10 +137,6 @@ int osmo_gpsd_open(void)
{
LOGP(DGPS, LOGL_INFO, "Connecting to gpsd at '%s:%s'\n", g.gpsd_host, g.gpsd_port);
- gps_bfd.data = NULL;
- gps_bfd.when = OSMO_FD_READ;
- gps_bfd.cb = osmo_gpsd_cb;
-
#if GPSD_API_MAJOR_VERSION >= 5
if (gps_open(g.gpsd_host, g.gpsd_port, &_gdata) == -1)
gdata = NULL;
@@ -153,15 +149,15 @@ int osmo_gpsd_open(void)
LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n");
return -1;
}
- gps_bfd.fd = gdata->gps_fd;
- if (gps_bfd.fd < 0)
- return gps_bfd.fd;
+ if (gdata->gps_fd < 0)
+ return gdata->gps_fd;
if (gps_stream(gdata, WATCH_ENABLE, NULL) == -1) {
LOGP(DGPS, LOGL_ERROR, "Error in gps_stream()\n");
return -1;
}
+ osmo_fd_setup(&gps_bfd, gdata->gps_fd, OSMO_FD_READ, osmo_gpsd_cb, NULL, 0);
osmo_fd_register(&gps_bfd);
return 0;
@@ -320,18 +316,17 @@ int osmo_serialgps_cb(struct osmo_fd *bfd, unsigned int what)
int osmo_serialgps_open(void)
{
int baud = 0;
+ int fd;
if (gps_bfd.fd > 0)
return 0;
LOGP(DGPS, LOGL_INFO, "Open GPS device '%s'\n", g.device);
- gps_bfd.data = NULL;
- gps_bfd.when = OSMO_FD_READ;
- gps_bfd.cb = osmo_serialgps_cb;
- gps_bfd.fd = open(g.device, O_RDONLY);
- if (gps_bfd.fd < 0)
- return gps_bfd.fd;
+ fd = open(g.device, O_RDONLY);
+ if (fd < 0)
+ return fd;
+ osmo_fd_setup(&gps_bfd, fd, OSMO_FD_READ, osmo_serialgps_cb, NULL, 0);
switch (g.baud) {
case 4800:
diff --git a/src/host/layer23/src/mobile/mncc_sock.c b/src/host/layer23/src/mobile/mncc_sock.c
index db76ef64..14adf071 100644
--- a/src/host/layer23/src/mobile/mncc_sock.c
+++ b/src/host/layer23/src/mobile/mncc_sock.c
@@ -231,11 +231,7 @@ static int mncc_sock_accept(struct osmo_fd *bfd, unsigned int flags)
return 0;
}
- conn_bfd->fd = rc;
- conn_bfd->when = OSMO_FD_READ;
- conn_bfd->cb = mncc_sock_cb;
- conn_bfd->data = state;
-
+ osmo_fd_setup(conn_bfd, rc, OSMO_FD_READ, mncc_sock_cb, state, 0);
if (osmo_fd_register(conn_bfd) != 0) {
LOGP(DMNCC, LOGL_ERROR, "Failed to register new connection fd\n");
close(conn_bfd->fd);
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index a755102f..66b2ea08 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -1322,10 +1322,7 @@ static int tool_accept(struct osmo_fd *fd, unsigned int flags)
con->server = srv;
- con->fd.fd = rc;
- con->fd.when = OSMO_FD_READ;
- con->fd.cb = un_tool_read;
- con->fd.data = con;
+ osmo_fd_setup(&con->fd, rc, OSMO_FD_READ, un_tool_read, con, 0);
if (osmo_fd_register(&con->fd) != 0) {
fprintf(stderr, "Failed to register the fd.\n");
talloc_free(con);
@@ -1389,7 +1386,7 @@ void parse_debug(const char *str)
int main(int argc, char **argv)
{
- int opt, flags;
+ int opt, flags, fd;
uint32_t tmp_load_address = ROMLOAD_ADDRESS;
const char *serial_dev = "/dev/ttyUSB1";
const char *layer2_un_path = "/tmp/osmocom_l2";
@@ -1442,12 +1439,13 @@ int main(int argc, char **argv)
dnload.filename = argv[optind];
}
- dnload.serial_fd.fd = osmo_serial_init(serial_dev, MODEM_BAUDRATE);
- if (dnload.serial_fd.fd < 0) {
+ fd = osmo_serial_init(serial_dev, MODEM_BAUDRATE);
+ if (fd < 0) {
fprintf(stderr, "Cannot open serial device %s\n", serial_dev);
exit(1);
}
+ osmo_fd_setup(&dnload.serial_fd, fd, OSMO_FD_READ, serial_read, NULL, 0);
if (osmo_fd_register(&dnload.serial_fd) != 0) {
fprintf(stderr, "Failed to register the serial.\n");
exit(1);
@@ -1458,9 +1456,6 @@ int main(int argc, char **argv)
flags |= O_NONBLOCK;
fcntl(dnload.serial_fd.fd, F_SETFL, flags);
- dnload.serial_fd.when = OSMO_FD_READ;
- dnload.serial_fd.cb = serial_read;
-
/* initialize the HDLC layer */
sercomm_init();
sercomm_register_rx_cb(SC_DLCI_CONSOLE, hdlc_console_cb);
diff --git a/src/host/trxcon/l1ctl_link.c b/src/host/trxcon/l1ctl_link.c
index 511ae0ca..2e2963a8 100644
--- a/src/host/trxcon/l1ctl_link.c
+++ b/src/host/trxcon/l1ctl_link.c
@@ -165,9 +165,7 @@ static int l1ctl_link_accept(struct osmo_fd *bfd, unsigned int flags)
l1l->wq.write_cb = l1ctl_link_write_cb;
l1l->wq.read_cb = l1ctl_link_read_cb;
- conn_bfd->when = OSMO_FD_READ;
- conn_bfd->data = l1l;
- conn_bfd->fd = cfd;
+ osmo_fd_setup(conn_bfd, cfd, OSMO_FD_READ, osmo_wqueue_bfd_cb, l1l, 0);
if (osmo_fd_register(conn_bfd) != 0) {
LOGP(DL1C, LOGL_ERROR, "Failed to register new connection fd\n");
@@ -255,6 +253,10 @@ struct l1ctl_link *l1ctl_link_init(void *tall_ctx, const char *sock_path)
/* Create a socket and bind handlers */
bfd = &l1l->listen_bfd;
+
+ /* Bind connection handler */
+ osmo_fd_setup(bfd, -1, OSMO_FD_READ, l1ctl_link_accept, l1l, 0);
+
rc = osmo_sock_unix_init_ofd(bfd, SOCK_STREAM, 0, sock_path,
OSMO_SOCK_F_BIND);
if (rc < 0) {
@@ -268,11 +270,6 @@ struct l1ctl_link *l1ctl_link_init(void *tall_ctx, const char *sock_path)
/* Bind shutdown handler */
l1l->shutdown_cb = l1ctl_shutdown_cb;
- /* Bind connection handler */
- bfd->cb = l1ctl_link_accept;
- bfd->when = OSMO_FD_READ;
- bfd->data = l1l;
-
/**
* To be able to accept first connection and
* drop others, it should be set to -1
diff --git a/src/host/virt_phy/src/l1ctl_sock.c b/src/host/virt_phy/src/l1ctl_sock.c
index d247bef0..7951f46e 100644
--- a/src/host/virt_phy/src/l1ctl_sock.c
+++ b/src/host/virt_phy/src/l1ctl_sock.c
@@ -125,10 +125,7 @@ static int l1ctl_sock_accept_cb(struct osmo_fd *ofd, unsigned int what)
}
lsc->l1ctl_sock = lsi;
- lsc->ofd.fd = fd;
- lsc->ofd.when = OSMO_FD_READ;
- lsc->ofd.cb = l1ctl_sock_data_cb;
- lsc->ofd.data = lsc;
+ osmo_fd_setup(&lsc->ofd, fd, OSMO_FD_READ, l1ctl_sock_data_cb, lsc, 0);
if (lsi->accept_cb) {
rc = lsi->accept_cb(lsc);
if (rc < 0) {
@@ -163,9 +160,7 @@ struct l1ctl_sock_inst *l1ctl_sock_init(
lsi = talloc_zero(ctx, struct l1ctl_sock_inst);
lsi->priv = NULL;
- lsi->ofd.data = lsi;
- lsi->ofd.when = OSMO_FD_READ;
- lsi->ofd.cb = l1ctl_sock_accept_cb;
+ osmo_fd_setup(&lsi->ofd, -1, OSMO_FD_READ, l1ctl_sock_accept_cb, lsi, 0);
rc = osmo_sock_unix_init_ofd(&lsi->ofd, SOCK_STREAM, 0, path, OSMO_SOCK_F_BIND);
if (rc < 0) {
diff --git a/src/host/virt_phy/src/shared/osmo_mcast_sock.c b/src/host/virt_phy/src/shared/osmo_mcast_sock.c
index b111a654..d0c5b6df 100644
--- a/src/host/virt_phy/src/shared/osmo_mcast_sock.c
+++ b/src/host/virt_phy/src/shared/osmo_mcast_sock.c
@@ -43,9 +43,7 @@ int mcast_client_sock_setup(struct osmo_fd *ofd, const char *mcast_group, uint16
int rc;
unsigned int flags = OSMO_SOCK_F_BIND | OSMO_SOCK_F_NO_MCAST_ALL | OSMO_SOCK_F_UDP_REUSEADDR;
- ofd->cb = fd_rx_cb;
- ofd->when = OSMO_FD_READ;
- ofd->data = osmo_fd_data;
+ osmo_fd_setup(ofd, -1, OSMO_FD_READ, fd_rx_cb, osmo_fd_data, 0);
/* Create mcast client socket */
rc = osmo_sock_init_ofd(ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP,