1*b75c6efcSBarry Smith /* 2*b75c6efcSBarry Smith 3*b75c6efcSBarry Smith Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92 4*b75c6efcSBarry Smith Updated by Richard Katz, katz@ldeo.columbia.edu 9/28/03 5*b75c6efcSBarry Smith */ 6*b75c6efcSBarry Smith 7*b75c6efcSBarry Smith #include <petscsys.h> 8*b75c6efcSBarry Smith #include <../src/sys/classes/viewer/impls/socket/socket.h> 9*b75c6efcSBarry Smith 10*b75c6efcSBarry Smith #include <errno.h> 11*b75c6efcSBarry Smith #include <ctype.h> 12*b75c6efcSBarry Smith #if defined(PETSC_HAVE_MACHINE_ENDIAN_H) 13*b75c6efcSBarry Smith #include <machine/endian.h> 14*b75c6efcSBarry Smith #endif 15*b75c6efcSBarry Smith #if defined(PETSC_HAVE_UNISTD_H) 16*b75c6efcSBarry Smith #include <unistd.h> 17*b75c6efcSBarry Smith #endif 18*b75c6efcSBarry Smith #if defined(PETSC_HAVE_SYS_SOCKET_H) 19*b75c6efcSBarry Smith #include <sys/socket.h> 20*b75c6efcSBarry Smith #endif 21*b75c6efcSBarry Smith #if defined(PETSC_HAVE_SYS_WAIT_H) 22*b75c6efcSBarry Smith #include <sys/wait.h> 23*b75c6efcSBarry Smith #endif 24*b75c6efcSBarry Smith #if defined(PETSC_HAVE_NETINET_IN_H) 25*b75c6efcSBarry Smith #include <netinet/in.h> 26*b75c6efcSBarry Smith #endif 27*b75c6efcSBarry Smith #if defined(PETSC_HAVE_NETDB_H) 28*b75c6efcSBarry Smith #include <netdb.h> 29*b75c6efcSBarry Smith #endif 30*b75c6efcSBarry Smith #if defined(PETSC_HAVE_FCNTL_H) 31*b75c6efcSBarry Smith #include <fcntl.h> 32*b75c6efcSBarry Smith #endif 33*b75c6efcSBarry Smith #if defined(PETSC_HAVE_IO_H) 34*b75c6efcSBarry Smith #include <io.h> 35*b75c6efcSBarry Smith #endif 36*b75c6efcSBarry Smith 37*b75c6efcSBarry Smith #if defined(PETSC_NEED_CLOSE_PROTO) 38*b75c6efcSBarry Smith PETSC_EXTERN int close(int); 39*b75c6efcSBarry Smith #endif 40*b75c6efcSBarry Smith 41*b75c6efcSBarry Smith #include <mex.h> 42*b75c6efcSBarry Smith #define PETSC_MEX_ERROR(a) \ 43*b75c6efcSBarry Smith { \ 44*b75c6efcSBarry Smith mexErrMsgTxt(a); \ 45*b75c6efcSBarry Smith return; \ 46*b75c6efcSBarry Smith } 47*b75c6efcSBarry Smith typedef struct { 48*b75c6efcSBarry Smith int onoff; 49*b75c6efcSBarry Smith int time; 50*b75c6efcSBarry Smith } Linger; 51*b75c6efcSBarry Smith /*-----------------------------------------------------------------*/ 52*b75c6efcSBarry Smith /* */ 53*b75c6efcSBarry Smith /*-----------------------------------------------------------------*/ 54*b75c6efcSBarry Smith PETSC_EXTERN void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 55*b75c6efcSBarry Smith { 56*b75c6efcSBarry Smith int t = 0; 57*b75c6efcSBarry Smith Linger linger; 58*b75c6efcSBarry Smith 59*b75c6efcSBarry Smith linger.onoff = 1; 60*b75c6efcSBarry Smith linger.time = 0; 61*b75c6efcSBarry Smith 62*b75c6efcSBarry Smith if (!nrhs) PETSC_MEX_ERROR("Needs one argument, the port"); 63*b75c6efcSBarry Smith t = (int)*mxGetPr(prhs[0]); 64*b75c6efcSBarry Smith 65*b75c6efcSBarry Smith if (setsockopt(t, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(Linger))) PETSC_MEX_ERROR("Setting linger"); 66*b75c6efcSBarry Smith if (close(t)) PETSC_MEX_ERROR("closing socket"); 67*b75c6efcSBarry Smith return; 68*b75c6efcSBarry Smith } 69*b75c6efcSBarry Smith 70*b75c6efcSBarry Smith int main(int argc, char **argv) 71*b75c6efcSBarry Smith { 72*b75c6efcSBarry Smith return 0; 73*b75c6efcSBarry Smith } 74