summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-07 13:36:28 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-07 15:32:47 -0700
commit918d58772595e7cd9907a7b08874196442fbf599 (patch)
tree17aad8aedbd3749b44932650ac065c647eff067b
parent6ca1ea376c7c6c9dc719d607b7684d87bcf96712 (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.ac2
-rw-r--r--src/misc.c131
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])
diff --git a/src/misc.c b/src/misc.c
index befa2c5..0e15adc 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -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;
}