diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-09-07 13:36:28 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-09-07 15:32:47 -0700 |
commit | 918d58772595e7cd9907a7b08874196442fbf599 (patch) | |
tree | 17aad8aedbd3749b44932650ac065c647eff067b | |
parent | 6ca1ea376c7c6c9dc719d607b7684d87bcf96712 (diff) |
Refactor Fatal I/O error handling into a common function
Reduce duplicated code in _IceRead() and _IceWrite()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/misc.c | 131 |
2 files changed, 48 insertions, 85 deletions
diff --git a/configure.ac b/configure.ac index 387a66b..e131ba8 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ XORG_WITH_XSLTPROC XORG_CHECK_SGML_DOCTOOLS(1.8) # Obtain compiler/linker options for dependencies -PKG_CHECK_MODULES(ICE, xproto xtrans) +PKG_CHECK_MODULES(ICE, [xproto >= 7.0.25 xtrans]) # Checks for library functions. AC_SEARCH_LIBS([arc4random_buf], [bsd]) @@ -63,7 +63,52 @@ IceAllocScratch ( return (iceConn->scratch); } +/* + * Fatal IO error. First notify each protocol's IceIOErrorProc + * callback, then invoke the application IO error handler. + */ + +static void _X_COLD +IceFatalIOError ( + IceConn iceConn +) +{ + iceConn->io_ok = False; + + if (iceConn->connection_status == IceConnectPending) + { + /* + * Don't invoke IO error handler if we are in the + * middle of a connection setup. + */ + + return; + } + + if (iceConn->process_msg_info) + { + for (int i = iceConn->his_min_opcode; + i <= iceConn->his_max_opcode; i++) + { + _IceProcessMsgInfo *process; + + process = &iceConn->process_msg_info[i - iceConn->his_min_opcode]; + if ((process != NULL) && process->in_use) + { + IceIOErrorProc IOErrProc = process->accept_flag ? + process->protocol->accept_client->io_error_proc : + process->protocol->orig_client->io_error_proc; + + if (IOErrProc) + (*IOErrProc) (iceConn); + } + } + } + + (*_IceIOErrorHandler) (iceConn); + return; +} /* * Output/Input buffer functions @@ -246,48 +291,7 @@ _IceRead ( } else { - /* - * Fatal IO error. First notify each protocol's IceIOErrorProc - * callback, then invoke the application IO error handler. - */ - - iceConn->io_ok = False; - - if (iceConn->connection_status == IceConnectPending) - { - /* - * Don't invoke IO error handler if we are in the - * middle of a connection setup. - */ - - return (1); - } - - if (iceConn->process_msg_info) - { - int i; - - for (i = iceConn->his_min_opcode; - i <= iceConn->his_max_opcode; i++) - { - _IceProcessMsgInfo *process; - - process = &iceConn->process_msg_info[ - i - iceConn->his_min_opcode]; - - if ((process != NULL) && process->in_use) - { - IceIOErrorProc IOErrProc = process->accept_flag ? - process->protocol->accept_client->io_error_proc : - process->protocol->orig_client->io_error_proc; - - if (IOErrProc) - (*IOErrProc) (iceConn); - } - } - } - - (*_IceIOErrorHandler) (iceConn); + IceFatalIOError (iceConn); return (1); } } @@ -354,48 +358,7 @@ _IceWrite ( #ifdef WIN32 errno = WSAGetLastError(); #endif - /* - * Fatal IO error. First notify each protocol's IceIOErrorProc - * callback, then invoke the application IO error handler. - */ - - iceConn->io_ok = False; - - if (iceConn->connection_status == IceConnectPending) - { - /* - * Don't invoke IO error handler if we are in the - * middle of a connection setup. - */ - - return; - } - - if (iceConn->process_msg_info) - { - int i; - - for (i = iceConn->his_min_opcode; - i <= iceConn->his_max_opcode; i++) - { - _IceProcessMsgInfo *process; - - process = &iceConn->process_msg_info[ - i - iceConn->his_min_opcode]; - - if (process->in_use) - { - IceIOErrorProc IOErrProc = process->accept_flag ? - process->protocol->accept_client->io_error_proc : - process->protocol->orig_client->io_error_proc; - - if (IOErrProc) - (*IOErrProc) (iceConn); - } - } - } - - (*_IceIOErrorHandler) (iceConn); + IceFatalIOError (iceConn); return; } |