[PATCH] libosmocore[master]: Register connecting socket for WRITE events

Max gerrit-no-reply at lists.osmocom.org
Wed Jan 18 16:32:51 UTC 2017


Review at  https://gerrit.osmocom.org/1624

Register connecting socket for WRITE events

Previously osmo_sock_init_ofd() created and register sockets for READ
events regardless of socket flags. Check socket flag and register for
WRITE events if it's a connect socket. This makes this function usable
for both bind and connect sockets.

Change-Id: I938de74c28df29221071913b769e7a2df9d041fa
---
M src/socket.c
1 file changed, 9 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/24/1624/1

diff --git a/src/socket.c b/src/socket.c
index cdafadd..dc22219 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -166,11 +166,12 @@
 /*! \brief fill \ref osmo_fd for a give sfd
  *  \param[out] ofd file descriptor (will be filled in)
  *  \param[in] sfd socket file descriptor
+ *  \param[in] when event type (read, write...)
  *  \returns socket fd on success; negative on error
  *
  * This function fills the \a ofd structure.
  */
-static inline int osmo_fd_init_ofd(struct osmo_fd *ofd, int sfd)
+static inline int fd_init_reg(struct osmo_fd *ofd, int sfd, unsigned int when)
 {
 	int rc;
 
@@ -178,7 +179,7 @@
 		return sfd;
 
 	ofd->fd = sfd;
-	ofd->when = BSC_FD_READ;
+	ofd->when = when;
 
 	rc = osmo_fd_register(ofd);
 	if (rc < 0) {
@@ -205,7 +206,10 @@
 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));
+	return fd_init_reg(ofd, osmo_sock_init(family, type, proto, host, port,
+					       flags),
+			   (flags & OSMO_SOCK_F_CONNECT) ? BSC_FD_WRITE :
+			   BSC_FD_READ);
 }
 
 /*! \brief Initialize a socket and fill \ref sockaddr
@@ -390,7 +394,8 @@
 int osmo_sock_unix_init_ofd(struct osmo_fd *ofd, uint16_t type, uint8_t proto,
 			    const char *socket_path, unsigned int flags)
 {
-	return osmo_fd_init_ofd(ofd, osmo_sock_unix_init(type, proto, socket_path, flags));
+	return fd_init_reg(ofd, osmo_sock_unix_init(type, proto, socket_path,
+						    flags), BSC_FD_READ);
 }
 
 #endif /* HAVE_SYS_SOCKET_H */

-- 
To view, visit https://gerrit.osmocom.org/1624
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I938de74c28df29221071913b769e7a2df9d041fa
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list