xref: /petsc/src/sys/classes/viewer/impls/socket/mex-scripts/sclose.c (revision 0619917b5a674bb687c64e7daba2ab22be99af31)
1 /*
2 
3         Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
4         Updated by Richard Katz, katz@ldeo.columbia.edu 9/28/03
5 */
6 
7 #include <petscsys.h>
8 #include <../src/sys/classes/viewer/impls/socket/socket.h>
9 
10 #include <errno.h>
11 #include <ctype.h>
12 #if defined(PETSC_HAVE_MACHINE_ENDIAN_H)
13   #include <machine/endian.h>
14 #endif
15 #if defined(PETSC_HAVE_UNISTD_H)
16   #include <unistd.h>
17 #endif
18 #if defined(PETSC_HAVE_SYS_SOCKET_H)
19   #include <sys/socket.h>
20 #endif
21 #if defined(PETSC_HAVE_SYS_WAIT_H)
22   #include <sys/wait.h>
23 #endif
24 #if defined(PETSC_HAVE_NETINET_IN_H)
25   #include <netinet/in.h>
26 #endif
27 #if defined(PETSC_HAVE_NETDB_H)
28   #include <netdb.h>
29 #endif
30 #if defined(PETSC_HAVE_FCNTL_H)
31   #include <fcntl.h>
32 #endif
33 #if defined(PETSC_HAVE_IO_H)
34   #include <io.h>
35 #endif
36 
37 #if defined(PETSC_NEED_CLOSE_PROTO)
38 PETSC_EXTERN int close(int);
39 #endif
40 
41 #include <mex.h>
42 #define PETSC_MEX_ERROR(a) \
43   { \
44     mexErrMsgTxt(a); \
45     return; \
46   }
47 typedef struct {
48   int onoff;
49   int time;
50 } Linger;
51 /*-----------------------------------------------------------------*/
52 /*                                                                 */
53 /*-----------------------------------------------------------------*/
54 PETSC_EXTERN void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
55 {
56   int    t = 0;
57   Linger linger;
58 
59   linger.onoff = 1;
60   linger.time  = 0;
61 
62   if (!nrhs) PETSC_MEX_ERROR("Needs one argument, the port");
63   t = (int)*mxGetPr(prhs[0]);
64 
65   if (setsockopt(t, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(Linger))) PETSC_MEX_ERROR("Setting linger");
66   if (close(t)) PETSC_MEX_ERROR("closing socket");
67   return;
68 }
69 
70 int main(int argc, char **argv)
71 {
72   return 0;
73 }
74