From 2353d7a7105d4ed6dad1f215c11b8e4a0f85ef35 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 30 Jul 2025 14:38:29 +0200 Subject: [PATCH] os: xtrans: replace _XSERVTransSetOption() by _XSERVTransNonBlock() The only option left is TRANS_NONBLOCKING, and we only enable and never disable it. Thus trim down the code into one function for exactly that. Signed-off-by: Enrico Weigelt, metux IT consult --- os/Xtrans.c | 33 ++------------------------------- os/Xtrans.h | 20 +++++++------------- os/connection.c | 4 ++-- 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/os/Xtrans.c b/os/Xtrans.c index 4020b6a36b..2b739a0dd8 100644 --- a/os/Xtrans.c +++ b/os/Xtrans.c @@ -553,34 +553,11 @@ _XSERVTransReopenCOTSServer (int trans_id, int fd, const char *port) return _XSERVTransReopen (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port); } -int _XSERVTransSetOption (XtransConnInfo ciptr, int option, int arg) - +int _XSERVTransNonBlock(XtransConnInfo ciptr) { int fd = ciptr->fd; int ret = 0; - prmsg (2,"SetOption(%d,%d,%d)\n", fd, option, arg); - - /* - * For now, all transport type use the same stuff for setting options. - * As long as this is true, we can put the common code here. Once a more - * complicated transport such as shared memory or an OSI implementation - * that uses the session and application libraries is implemented, this - * code may have to move to a transport dependent function. - * - * ret = ciptr->transptr->SetOption (ciptr, option, arg); - */ - - switch (option) - { - case TRANS_NONBLOCKING: - switch (arg) - { - case 0: - /* Set to blocking mode */ - break; - case 1: /* Set to non-blocking mode */ - #if defined(O_NONBLOCK) ret = fcntl (fd, F_GETFL, 0); if (ret != -1) @@ -606,13 +583,7 @@ int _XSERVTransSetOption (XtransConnInfo ciptr, int option, int arg) #endif /* WIN32 */ #endif /* FIOSNBIO */ #endif /* O_NONBLOCK */ - break; - default: - /* Unknown option */ - break; - } - break; - } + return ret; } diff --git a/os/Xtrans.h b/os/Xtrans.h index ffc79cf35c..3dc45a6ae6 100644 --- a/os/Xtrans.h +++ b/os/Xtrans.h @@ -129,14 +129,6 @@ struct iovec { typedef struct _XtransConnInfo *XtransConnInfo; - -/* - * Transport Option definitions - */ - -#define TRANS_NONBLOCKING 1 - - /* * Return values of Connect (0 is success) */ @@ -190,11 +182,13 @@ XtransConnInfo _XSERVTransReopenCOTSServer( const char * /* port */ ); -int _XSERVTransSetOption( - XtransConnInfo, /* ciptr */ - int, /* option */ - int /* arg */ -); +/* + * set connection to non-blocking mode + * + * @param conn the connection to set to non-blocking mode + * @return zero on success or errno value + */ +int _XSERVTransNonBlock(XtransConnInfo conn); int _XSERVTransCreateListener( XtransConnInfo, /* ciptr */ diff --git a/os/connection.c b/os/connection.c index 1829d66d05..0d1876485d 100644 --- a/os/connection.c +++ b/os/connection.c @@ -690,7 +690,7 @@ EstablishNewConnections(int curconn, int ready, void *data) newconn = _XSERVTransGetConnectionNumber(new_trans_conn); - _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); + _XSERVTransNonBlock(new_trans_conn); if (trans_conn->flags & TRANS_NOXAUTH) new_trans_conn->flags = new_trans_conn->flags | TRANS_NOXAUTH; @@ -1071,7 +1071,7 @@ AddClientOnOpenFD(int fd) if (ciptr == NULL) return FALSE; - _XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1); + _XSERVTransNonBlock(ciptr); ciptr->flags |= TRANS_NOXAUTH; connect_time = GetTimeInMillis();