/* @(#)client.c 17.1.1.1 (ESO-DMD) 01/25/02 17:37:01 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*++++++++++++++++++ osx (socket) based client interfaces +++++++++++++++++++ .LANGUAGE C .IDENTIFICATION Module consubs.c .AUTHOR K. Banse ESO - Garching .KEYWORDS background Midas, communication .ENVIRONMENT UNIX only .COMMENTS holds ClientInit, ClientClose, ClientFree, Clientinfo, ClientWait, ClientWrite, ClientRead, ClientKWrite, ClientKRead ida_vuelta .REMARKS the corresponding server interfaces are in /midas/version/monit/prepz1.c .VERSION [1.00] 940425: creation .VERSION [1.05] 941018: use serv_buf.code_id as function code 981202 ----------------------------------------------------------------------------*/ #include #include #include #include #include #define CLIENT_OVF -99 static char *servname[2] = { (char *)NULL, (char *)NULL }; static int first_bytes; static int osxclid[MAX_BACK] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; /* sync with xconndef.h! */ /* */ int ClientInit(shost,sunit,idclient,retosx) char *shost, *sunit; int *idclient; int *retosx; { int osxchan, port; int retsize, jsecs, msecs, jindx, osx_cod; int i, mode, np; for (i=0; i= MAX_BACK)) return (-9); *fd = osxclid[idclient]; return (0); } int ClientClose(idclient,retosx) /* close connection to server */ int idclient, *retosx; { int osxchan, kk; if ((idclient < 0) || (idclient >= MAX_BACK)) return (-9); osxchan = osxclid[idclient]; osxclid[idclient] = -1; /* free entry again */ kk = osxclose (osxchan); if (kk != 0) *retosx = oserror; return(kk); } /* */ int ClientWait(idclient,timo) int idclient, timo; { int osxchan; int jsecs, msecs; int np, myret; if ((idclient < 0) || (idclient >= MAX_BACK)) return (-9); osxchan = osxclid[idclient]; if (timo < 0) /* -1 = wait until we get data */ { jsecs = 0; msecs = 100; osx_poll: np = osxinfo(osxchan,jsecs,msecs); if ((np == NOCONN) || (np == -1)) return (-1); /* no connection ! */ if (np != DATARDY) goto osx_poll; return (1); /* we got data */ } else { jsecs = timo; msecs = 0; np = osxinfo(osxchan,jsecs,msecs); if ((np == NOCONN) || (np == -1)) return (-1); /* no connection ! */ if (np == DATARDY) return (1); /* we got data */ else return (0); /* NODATA */ } } /* */ int ClientWrite(idclient,comline,retosx) int idclient; char *comline; int *retosx; { int txtlen, np, myret; int retsize; char *charbuf; if ((idclient < 0) || (idclient >= MAX_BACK)) return (-9); txtlen = (int)strlen(comline) + 1; np = ((txtlen % III_SIZE) == 0) ? (txtlen/III_SIZE) : (txtlen/III_SIZE + 1); serv_buf.nobyt = np*III_SIZE + BUFHEAD; serv_buf.code_id = 10; charbuf = (char *)(serv_buf.data.in); (void)strcpy(charbuf,comline); np = ida_vuelta(2,idclient,&retsize,&myret); /* don't wait */ if (np != 0) *retosx = myret; return (np); } /* */ int ClientRead(idclient,comline,bgstat,retosx) int idclient; char *comline; int *bgstat; int *retosx; { int txtlen, np, retsize, myret; char *charbuf; if ((idclient < 0) || (idclient >= MAX_BACK)) return (-9); np = ida_vuelta(3,idclient,&retsize,&myret); /* wait for return */ if (np != 0) *retosx = myret; *bgstat = serv_ret.code; /* status of command executed by server */ return (np); } /* */ int ClientKWrite(idclient,typ,comline,sendbuf,karr,retosx) int idclient; int typ; char *comline; char *sendbuf; int *karr; /* 4 elements */ int *retosx; { register int nr; int retsize; int txtlen, np, myret, m; char *charbuf; if ((idclient < 0) || (idclient >= MAX_BACK)) return (-9); txtlen = (int)strlen(comline) + 1; np = ((txtlen % III_SIZE) == 0) ? (txtlen/III_SIZE) : (txtlen/III_SIZE + 1); serv_buf.nobyt = np*III_SIZE + BUFHEAD; serv_buf.code_id = 20; charbuf = (char *)(serv_buf.data.in); (void)strcpy(charbuf,comline); np = ida_vuelta(1,idclient,&retsize,&myret); /* send 1. part */ if (np != 0) { *retosx = myret; return (np); } for (nr=0; nr<4; nr++) serv_buf.data.in[nr] = karr[nr]; if (typ == 1) { int *ipntr; ipntr = (int *) sendbuf; for (nr=4; nr= MAX_BACK)) return (-9); txtlen = (int)strlen(comline) + 1; np = ((txtlen % III_SIZE) == 0) ? (txtlen/III_SIZE) : (txtlen/III_SIZE + 1); serv_buf.nobyt = np*III_SIZE + BUFHEAD; serv_buf.code_id = 30; charbuf = (char *)(serv_buf.data.in); (void)strcpy(charbuf,comline); np = ida_vuelta(1,idclient,&retsize,&myret); /* write + read */ if (np != 0) *retosx = myret; else { for (nr=0; nr<4; nr++) karr[nr] = serv_ret.data.in[nr]; if (typ == 1) { int *ipntr; ipntr = (int *) retbuf; for (nr=4; nr 0) { osx_cod = osxread(osxchan,(char *)&serv_ret.data,n_bytes); if (osx_cod == -1) { *retosx = oserror; return(-1); } } *size = n_bytes; /* return actual no. of returned bytes */ return (0); }