[PATCH:xscope 21/24] Refactor fd closing into CloseFD helper function
Alan Coopersmith
alan.coopersmith at oracle.com
Fri Aug 31 22:18:03 PDT 2012
All versions now perform same check for XtransConn data to decide
whether to use _X11TransClose or regular close, which is needed for
being able to read data from pre-recorded files instead of live sockets.
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
fd.c | 23 +++++++++++++++++------
fd.h | 1 +
scope.c | 12 +++---------
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/fd.c b/fd.c
index 7b6accd..176c73e 100644
--- a/fd.c
+++ b/fd.c
@@ -196,20 +196,31 @@ GetXTransConnInfo(FD fd)
/* ************************************************************ */
-static void
-EOFonFD(FD fd)
+void
+CloseFD (FD fd)
{
- enterprocedure("EOFonFD");
- debug(128, (stderr, "EOF on %d\n", fd));
#ifdef USE_XTRANS
- if (FDD[fd].trans_conn)
- _X11TransClose(FDD[fd].trans_conn);
+ XtransConnInfo conn = GetXTransConnInfo(fd);
+
+ if (conn)
+ _X11TransClose(conn);
else
#endif
close(fd);
+
NotUsingFD(fd);
}
+/* ************************************************************ */
+
+static void
+EOFonFD(FD fd)
+{
+ enterprocedure("EOFonFD");
+ debug(128, (stderr, "EOF on %d\n", fd));
+ CloseFD(fd);
+}
+
FD
AcceptConnection(FD ConnectionSocket)
{
diff --git a/fd.h b/fd.h
index 85cdd25..0a65205 100644
--- a/fd.h
+++ b/fd.h
@@ -87,6 +87,7 @@ extern fd_set BlockedReadDescriptors; /* bit map of FD's blocked from reading
extern int HighestFD; /* highest FD in use -- for select */
extern void InitializeFD(void);
+extern void CloseFD (FD fd);
extern void UsingFD(FD fd, void (*Handler) (int), void (*FlushHandler) (int),
XtransConnInfo trans_conn);
diff --git a/scope.c b/scope.c
index 9b767ab..2a62601 100644
--- a/scope.c
+++ b/scope.c
@@ -951,15 +951,9 @@ CloseConnection(FD fd)
StopClientConnection(ServerHalf(fd));
StopServerConnection(ClientHalf(fd));
-#ifdef USE_XTRANS
- _X11TransClose(GetXTransConnInfo(fd));
- _X11TransClose(GetXTransConnInfo(FDPair(fd)));
-#else
- close(fd);
- close(FDPair(fd));
-#endif
- NotUsingFD(fd);
- NotUsingFD(FDPair(fd));
+ CloseFD(fd);
+ CloseFD(FDPair(fd));
+
if (TerminateClose)
exit(0);
}
--
1.7.9.2
More information about the xorg-devel
mailing list