mirror of https://gerrit.osmocom.org/osmo-pcap
client: Move to osmo_sock_init2_ofd()
We can simplify the code even further by using the osmo_fd version of osmo_sock_init2() called osmo_sock_init2_ofd(), which takes care of filling the osmo_fd.fd member and registering the socket in the select loop. Change-Id: Ibf1480e7dee287db77a19bb9f0254edddf7706ab
This commit is contained in:
parent
f266924bac
commit
5f071cd2c6
|
@ -228,20 +228,19 @@ void osmo_client_send_link(struct osmo_pcap_client_conn *conn)
|
|||
|
||||
void osmo_client_connect(struct osmo_pcap_client_conn *conn)
|
||||
{
|
||||
int fd;
|
||||
int rc;
|
||||
|
||||
osmo_client_disconnect(conn);
|
||||
|
||||
conn->wqueue.read_cb = read_cb;
|
||||
conn->wqueue.write_cb = write_cb;
|
||||
conn->wqueue.bfd.when = BSC_FD_READ;
|
||||
osmo_wqueue_clear(&conn->wqueue);
|
||||
|
||||
fd = osmo_sock_init2(AF_INET, SOCK_STREAM, IPPROTO_TCP,
|
||||
rc = osmo_sock_init2_ofd(&conn->wqueue.bfd, AF_INET, SOCK_STREAM, IPPROTO_TCP,
|
||||
conn->source_ip, 0,
|
||||
conn->srv_ip, conn->srv_port,
|
||||
OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT | OSMO_SOCK_F_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
if (rc < 0) {
|
||||
LOGP(DCLIENT, LOGL_ERROR,
|
||||
"Failed to connect conn=%s to %s:%d\n",
|
||||
conn->name, conn->srv_ip, conn->srv_port);
|
||||
|
@ -249,14 +248,6 @@ void osmo_client_connect(struct osmo_pcap_client_conn *conn)
|
|||
return;
|
||||
}
|
||||
|
||||
conn->wqueue.bfd.fd = fd;
|
||||
if (osmo_fd_register(&conn->wqueue.bfd) != 0) {
|
||||
LOGP(DCLIENT, LOGL_ERROR,
|
||||
"Failed to register to BFD conn=%s\n", conn->name);
|
||||
lost_connection(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_CONNECT]);
|
||||
conn->wqueue.bfd.cb = conn_cb;
|
||||
conn->wqueue.bfd.data = conn;
|
||||
|
|
Loading…
Reference in New Issue