Actual source code: closeport.c
1: /* This was part of the MatlabSockettool package.
2:
3: Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
4: Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03
5: */
7: #include petsc.h
8: #if defined(PETSC_NEEDS_UTYPE_TYPEDEFS)
9: typedef unsigned char u_char;
10: typedef unsigned short u_short;
11: typedef unsigned short ushort;
12: typedef unsigned int u_int;
13: typedef unsigned long u_long;
14: #endif
15: #include <stdio.h>
16: #include <errno.h>
17: #include <sys/types.h>
18: #include <sys/socket.h>
19: #include <sys/wait.h>
20: #include <netinet/in.h>
21: #include <netdb.h>
22: #include <fcntl.h>
23: #include src/sys/src/viewer/impls/socket/socket.h
24: #include "mex.h"
25: #define PETSC_MEX_ERROR(a) {fprintf(stdout,"CLOSEPORT: %s \n",a); return ;}
26: typedef struct { int onoff; int time; } Linger;
27: /*-----------------------------------------------------------------*/
28: /* */
29: /*-----------------------------------------------------------------*/
32: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
33: {
34: int t = 0;
35: Linger linger;
37: linger.onoff = 1;
38: linger.time = 0;
40: if (!nrhs) PETSC_MEX_ERROR("Needs one argument, the port");
41: t = (int)*mxGetPr(prhs[0]);
43: if (setsockopt(t,SOL_SOCKET,SO_LINGER,(char*)&linger,sizeof(Linger)))
44: PETSC_MEX_ERROR("Setting linger");
45: if (close(t)) PETSC_MEX_ERROR("closing socket");
46: return;
47: }