Actual source code: sclose.c
petsc-3.7.3 2016-08-01
1: /*
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: */
7: #include <petscsys.h>
8: #include <../src/sys/classes/viewer/impls/socket/socket.h>
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
37: #if defined(PETSC_NEED_CLOSE_PROTO)
38: PETSC_EXTERN int close(int);
39: #endif
41: #include <mex.h>
42: #define PETSC_MEX_ERROR(a) {mexErrMsgTxt(a); return;}
43: typedef struct { int onoff; int time; } Linger;
44: /*-----------------------------------------------------------------*/
45: /* */
46: /*-----------------------------------------------------------------*/
49: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
50: {
51: int t = 0;
52: Linger linger;
54: linger.onoff = 1;
55: linger.time = 0;
57: if (!nrhs) PETSC_MEX_ERROR("Needs one argument, the port");
58: t = (int)*mxGetPr(prhs[0]);
60: if (setsockopt(t,SOL_SOCKET,SO_LINGER,(char*)&linger,sizeof(Linger))) PETSC_MEX_ERROR("Setting linger");
61: if (close(t)) PETSC_MEX_ERROR("closing socket");
62: return;
63: }