/* * Copyright (c) 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. */ #pragma implementation #include "ILLPSocket.h" #ifdef PROTOGEN # include "exception.h" # include "logfile.h" #else # include # define ERROR(fmt, args...) { fprintf(stderr, fmt "\n" , ## args); exit(1); } # define FATAL(fmt, args...) { fprintf(stderr, fmt "\n" , ## args); abort(); } # define WARNING(fmt, args...) { fprintf(stderr, fmt "\n" , ## args); } #endif #include /* A simple ILLP implementation w/o OOB messages and no access control (yet) ILLP will be dropped on the long run, it is too device specific. */ #define A_STX 0x02 /********************************************************************** * ctor, dtor, and copy **********************************************************************/ ILLPSocket::ILLPSocket(const char *address, const char *, size_t) : Socket(address) {} ILLPSocket::ILLPSocket() : Socket() {} ILLPSocket::~ILLPSocket() { if(state() & connected) close(); } Socket *ILLPSocket::ctor(const char *address, const char *param, size_t parlen) { return new ILLPSocket(address, param, parlen); } Socket *ILLPSocket::ctor() { return new ILLPSocket(); } /********************************************************************** * socket methods **********************************************************************/ Socket *ILLPSocket::accept(flags_t mode) { if(_lower_level == NULL) ERROR("lower level is missing"); ILLPSocket *is = new ILLPSocket; is->_lower_level = _lower_level->accept(mode); char c; do { is->_lower_level->recv(&c,1); } while(c != A_STX); return is; } bool ILLPSocket::connect(flags_t mode) { if(_lower_level == NULL) ERROR("lower level is missing"); _lower_level->connect(mode); char buf[1024]; gethostname(buf,1024); int n = strlen(buf); buf[n++] = A_STX; _lower_level->send(buf,n); return true; }