Date: 2022-08-02T03:13:15+00:00

Actual source code: sclose.c

      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: /*-----------------------------------------------------------------*/
     47: PETSC_EXTERN void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
     48: {
     49:   int    t = 0;
     50:   Linger linger;

     52:   linger.onoff = 1;
     53:   linger.time  = 0;

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

     58:   if (setsockopt(t,SOL_SOCKET,SO_LINGER,(char*)&linger,sizeof(Linger))) PETSC_MEX_ERROR("Setting linger");
     59:   if (close(t)) PETSC_MEX_ERROR("closing socket");
     60:   return;
     61: }

     63: int main(int argc, char **argv)
     64: {
     65:   return 0;
     66: }