Updated ph-socket interface

This commit is contained in:
Andreas Eversberg 2023-01-24 18:07:52 +01:00
parent de54466eb5
commit 9f63e0e965
1 changed files with 15 additions and 7 deletions

View File

@ -32,14 +32,14 @@
#include "logging.h"
#include "ph_socket.h"
int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what);
int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what);
static int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what);
static int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what);
static void ph_socket_timeout_cb(void *data);
static void open_connection(ph_socket_t *s)
{
uint8_t enable = PH_CTRL_UNBLOCK;
int rc;
int rc, flags;
if (s->connect_ofd.fd > 0)
return;
@ -54,8 +54,12 @@ static void open_connection(ph_socket_t *s)
s->connect_ofd.fd = rc;
s->connect_ofd.data = s;
s->connect_ofd.when = BSC_FD_READ;
s->connect_ofd.cb = ph_socket_listen_cb;
s->connect_ofd.cb = ph_socket_connect_cb;
osmo_fd_register(&s->connect_ofd);
/* set nonblocking io, because we do multiple reads when handling read event */
flags = fcntl(s->connect_ofd.fd, F_GETFL);
flags |= O_NONBLOCK;
fcntl(s->connect_ofd.fd, F_SETFL, flags);
/* connect */
rc = connect(s->connect_ofd.fd, (struct sockaddr *)&s->sock_address, sizeof(s->sock_address));
if (rc < 0 && errno != EAGAIN) {
@ -176,12 +180,12 @@ void ph_socket_exit(ph_socket_t *s)
osmo_timer_del(&s->retry_timer);
}
int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what)
static int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what)
{
ph_socket_t *s = ofd->data;
struct sockaddr_un sock_address;
uint8_t enable = PH_CTRL_UNBLOCK;
int rc;
int rc, flags;
socklen_t sock_len = sizeof(sock_address);
/* see if there is an incoming connection */
@ -198,6 +202,10 @@ int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)
s->connect_ofd.when = BSC_FD_READ;
s->connect_ofd.cb = ph_socket_connect_cb;
osmo_fd_register(&s->connect_ofd);
/* set nonblocking io, because we do multiple reads when handling read event */
flags = fcntl(s->connect_ofd.fd, F_GETFL);
flags |= O_NONBLOCK;
fcntl(s->connect_ofd.fd, F_SETFL, flags);
/* reset rx buffer */
s->rx_header_index = 0;
s->rx_data_index = 0;
@ -209,7 +217,7 @@ int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)
return 0;
}
int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned __attribute__((unused)) int what)
static int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned __attribute__((unused)) int what)
{
ph_socket_t *s = ofd->data;
int rc;