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