summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/socket.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/socket.c b/src/socket.c
index 844ebd3b..567939b7 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -150,24 +150,16 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
return sfd;
}
-/*! \brief Initialize a socket and fill \ref osmo_fd
+/*! \brief fill \ref osmo_fd for a give sfd
* \param[out] ofd file descriptor (will be filled in)
- * \param[in] family Address Family like AF_INET, AF_INET6, AF_UNSPEC
- * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
- * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
- * \param[in] host remote host name or IP address in string form
- * \param[in] port remote port number in host byte order
- * \param[in] flags flags like \ref OSMO_SOCK_F_CONNECT
+ * \param[in] sfd socket file descriptor
*
- * This function creates (and optionall binds/connects) a socket using
- * \ref osmo_sock_init, but also fills the \a ofd structure.
+ * This function fills the \a ofd structure.
*/
-int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
- const char *host, uint16_t port, unsigned int flags)
+static inline int osmo_fd_init_ofd(struct osmo_fd *ofd, int sfd)
{
- int sfd, rc;
+ int rc;
- sfd = osmo_sock_init(family, type, proto, host, port, flags);
if (sfd < 0)
return sfd;
@@ -183,6 +175,24 @@ int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
return sfd;
}
+/*! \brief Initialize a socket and fill \ref osmo_fd
+ * \param[out] ofd file descriptor (will be filled in)
+ * \param[in] family Address Family like AF_INET, AF_INET6, AF_UNSPEC
+ * \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
+ * \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP
+ * \param[in] host remote host name or IP address in string form
+ * \param[in] port remote port number in host byte order
+ * \param[in] flags flags like \ref OSMO_SOCK_F_CONNECT
+ *
+ * This function creates (and optionall binds/connects) a socket using
+ * \ref osmo_sock_init, but also fills the \a ofd structure.
+ */
+int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
+ const char *host, uint16_t port, unsigned int flags)
+{
+ return osmo_fd_init_ofd(ofd, osmo_sock_init(family, type, proto, host, port, flags));
+}
+
/*! \brief Initialize a socket and fill \ref sockaddr
* \param[out] ss socket address (will be filled in)
* \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM
@@ -362,22 +372,7 @@ err:
int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto,
const char *socket_path, unsigned int flags)
{
- int sfd, rc;
-
- sfd = osmo_sock_unix_init(type, proto, socket_path, flags);
- if (sfd < 0)
- return sfd;
-
- ofd->fd = sfd;
- ofd->when = BSC_FD_READ;
-
- rc = osmo_fd_register(ofd);
- if (rc < 0) {
- close(sfd);
- return rc;
- }
-
- return sfd;
+ return osmo_fd_init_ofd(ofd, osmo_sock_unix_init(type, proto, socket_path, flags));
}
#endif /* HAVE_SYS_SOCKET_H */