Actual source code: sclose.c

petsc-3.3-p7 2013-05-11
  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: */

  7: #include <petscsys.h>
  8: #include <../src/sys/viewer/impls/socket/socket.h>

 10: #include <errno.h>
 11: #if defined(PETSC_HAVE_STDLIB_H)
 12: #include <stdlib.h>
 13: #endif
 14: #include <sys/types.h>
 15: #include <ctype.h>
 16: #if defined(PETSC_HAVE_MACHINE_ENDIAN_H)
 17: #include <machine/endian.h>
 18: #endif
 19: #if defined(PETSC_HAVE_UNISTD_H)
 20: #include <unistd.h>
 21: #endif
 22: #if defined(PETSC_HAVE_SYS_SOCKET_H)
 23: #include <sys/socket.h>
 24: #endif
 25: #if defined(PETSC_HAVE_SYS_WAIT_H)
 26: #include <sys/wait.h>
 27: #endif
 28: #if defined(PETSC_HAVE_NETINET_IN_H)
 29: #include <netinet/in.h>
 30: #endif
 31: #if defined(PETSC_HAVE_NETDB_H)
 32: #include <netdb.h>
 33: #endif
 34: #if defined(PETSC_HAVE_FCNTL_H)
 35: #include <fcntl.h>
 36: #endif
 37: #if defined(PETSC_HAVE_IO_H)
 38: #include <io.h>
 39: #endif

 41: EXTERN_C_BEGIN
 42: #if defined(PETSC_NEED_CLOSE_PROTO)
 43: extern int close(int);
 44: #endif
 45: EXTERN_C_END

 47: #include <mex.h>
 48: #define PETSC_MEX_ERROR(a) {mexErrMsgTxt(a); return ;}
 49: typedef struct { int onoff; int time; } Linger;
 50: /*-----------------------------------------------------------------*/
 51: /*                                                                 */
 52: /*-----------------------------------------------------------------*/
 55: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
 56: {
 57:   int    t = 0;
 58:   Linger linger;

 60:   linger.onoff = 1;
 61:   linger.time  = 0;

 63:   if (!nrhs) PETSC_MEX_ERROR("Needs one argument, the port");
 64:   t = (int)*mxGetPr(prhs[0]);

 66:   if (setsockopt(t,SOL_SOCKET,SO_LINGER,(char*)&linger,sizeof(Linger)))
 67:     PETSC_MEX_ERROR("Setting linger");
 68:   if (close(t)) PETSC_MEX_ERROR("closing socket");
 69:   return;
 70: }