pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmocore/+/41667?usp=email )
Change subject: socket: Introduce API osmo_sock_set_nonblock()
......................................................................
socket: Introduce API osmo_sock_set_nonblock()
Change-Id: I8b9011df0ff1fe8303e1effcc9906d9c3350c66e
---
M TODO-RELEASE
M include/osmocom/core/socket.h
M src/core/libosmocore.map
M src/core/socket.c
4 files changed, 15 insertions(+), 2 deletions(-)
Approvals:
osmith: Looks good to me, approved
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 0ed7189..1562b38 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public
release: c:r:0.
#library what description / commit summary line
+core added osmo_sock_set_nonblock()
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index ea73cda..088a444 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -219,6 +219,7 @@
int osmo_sock_set_dscp(int fd, uint8_t dscp);
int osmo_sock_set_priority(int fd, int prio);
+int osmo_sock_set_nonblock(int fd, int on);
int osmo_sock_sctp_get_peer_addr_info(int fd, struct sctp_paddrinfo *pinfo,
size_t *pinfo_cnt);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index 198b31e..166eea9 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -454,6 +454,7 @@
osmo_sock_multiaddr_get_name_buf;
osmo_sock_sctp_get_peer_addr_info;
osmo_sock_set_dscp;
+osmo_sock_set_nonblock;
osmo_sock_set_priority;
osmo_sock_unix_init;
osmo_sock_unix_init_ofd;
diff --git a/src/core/socket.c b/src/core/socket.c
index 915c70e..01093bb 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -133,12 +133,12 @@
static int socket_helper_tail(int sfd, unsigned int flags)
{
- int rc, on = 1;
+ int rc;
uint8_t dscp = GET_OSMO_SOCK_F_DSCP(flags);
uint8_t prio = GET_OSMO_SOCK_F_PRIO(flags);
if (flags & OSMO_SOCK_F_NONBLOCK) {
- if (ioctl(sfd, FIONBIO, (unsigned char *)&on) < 0) {
+ if (osmo_sock_set_nonblock(sfd, 1) < 0) {
LOGP(DLGLOBAL, LOGL_ERROR,
"cannot set this socket unblocking: %s\n",
strerror(errno));
@@ -2746,6 +2746,16 @@
return setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
}
+/*! Set the socket as non-blocking or blocking.
+ * \param[in] fd File descriptor of the socket
+ * \param[in] on set to 1 to set as non-blocking, 0 to set as blocking.
+ * \returns 0 on success; negative on error. */
+int osmo_sock_set_nonblock(int fd, int on)
+{
+ /* and write it back to the kernel */
+ return ioctl(fd, FIONBIO, (unsigned char *)&on);
+}
+
#ifdef HAVE_LIBSCTP
/*! Fill in array of struct sctp_paddrinfo with each of the remote addresses
of an SCTP socket
* \param[in] fd file descriptor of SCTP socket
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41667?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I8b9011df0ff1fe8303e1effcc9906d9c3350c66e
Gerrit-Change-Number: 41667
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>