diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-07-21 11:36:18 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-10-02 22:16:08 -0700 |
commit | 5cf76eb8f489f6c4d1ba76bf6fe782c3cf45803d (patch) | |
tree | ce1c874488677c497519778a273cacde299f7990 | |
parent | d325cc4930d7e04bd09d54548c6dc58329cfc15b (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.c | 23 | ||||
-rw-r--r-- | fd.h | 1 | ||||
-rw-r--r-- | scope.c | 12 |
3 files changed, 21 insertions, 15 deletions
@@ -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) { @@ -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); @@ -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); } |