/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * 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 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" #include "llpdrv.h" #include "socket.h" #include "intern.h" #include #include #include #include #include #ifdef _AIX #include #endif result send_oob(FILE* fp, char data) { fd_set wrfds; int nfds; int fd = fileno(fp); int retry_cnt = 10; if(fpurge(fp) == EOF) { syslog(LOG_ERR, "fpurge: %m"); return FAIL; } retry: FD_ZERO(&wrfds); FD_SET(fd, &wrfds); nfds = select(FD_SETSIZE, NULL, &wrfds, NULL, NULL); if (nfds < 0) { syslog(LOG_ERR, "select: %m"); return FAIL; } else if(nfds == 0) { syslog(LOG_WARNING, "select: timeout or interrupt"); return FAIL; } if(send(fileno(fp), &data, 1, MSG_OOB) < 1) { syslog(LOG_ERR, "send MSG_OOB: %m"); usleep(500000); if(retry_cnt-- > 0) goto retry; else return FAIL; } return SUCCESS; } int recv_oob(FILE* fp) { bool atmark = FALSE; int fd = fileno(fp); char waist[1024]; char c; if(fpurge(fp) == EOF) { syslog(LOG_ERR, "fpurge: %m"); return FAIL; } do { if(ioctl(fd, SIOCATMARK, &atmark) == FAIL) { syslog(LOG_ERR, "SIOCATMARK: %m"); return FAIL; } if(atmark) break; switch(read(fd, waist, 1024)) { case FAIL: syslog(LOG_ERR, "getc: %m"); return FAIL; case 0: /* connection closed */ syslog(LOG_ERR, "connection closed by server"); return FAIL; } } while(TRUE); if(recv(fd, &c, 1, MSG_OOB) < 1) { syslog(LOG_ERR, "recv: %m"); return FAIL; } return c; }