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: */
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 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,Matrix *plhs[],int nrhs,Matrix *prhs[])
33: {
34: int t = 0;
35: Linger linger;
37: linger.onoff = 1;
38: linger.time = 0;
40: if (!nrhs) 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: ERROR("Setting linger");
45: if (close(t)) ERROR("closing socket");
46: return;
47: }