summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2012-07-21 11:36:18 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2012-10-02 22:16:08 -0700
commit5cf76eb8f489f6c4d1ba76bf6fe782c3cf45803d (patch)
treece1c874488677c497519778a273cacde299f7990
parentd325cc4930d7e04bd09d54548c6dc58329cfc15b (diff)
Refactor fd closing into CloseFD helper function
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@oracle.com> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
-rw-r--r--fd.c23
-rw-r--r--fd.h1
-rw-r--r--scope.c12
3 files changed, 21 insertions, 15 deletions
diff --git a/fd.c b/fd.c
index 4ee9a3e..8ac3e89 100644
--- a/fd.c
+++ b/fd.c
@@ -198,20 +198,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..59b4889 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 89049aa..1234f82 100644
--- a/scope.c
+++ b/scope.c
@@ -956,15 +956,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);
}