From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/net/isocket.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/net/isocket.h (limited to 'src/net/isocket.h') diff --git a/src/net/isocket.h b/src/net/isocket.h new file mode 100644 index 0000000..5ca1ec3 --- /dev/null +++ b/src/net/isocket.h @@ -0,0 +1,68 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ISOCKETH +#define ISOCKETH + +#include +#include +#include +#include +#include +#include + +class isocket : public pipe_stream { +public: + isocket(const in_addr& ia,int port,int backlog); + isocket(int f,const sockaddr_in& ia); + ~isocket() { close(); } + + void close() { if(fd>=0) { ::close(fd); fd=-1; }} + + int getfd() const { return fd; } + int family() const { return sa.sin_family; } + int port() const { return ntohs(sa.sin_port); } + in_addr address() const { return sa.sin_addr; } + + void reuse(int ok) { set(SOL_SOCKET,SO_REUSEADDR,ok); } + void nodelay(int ok) { set(IPPROTO_TCP,TCP_NODELAY,ok); } + void keepalive(int ok) { set(SOL_SOCKET,SO_KEEPALIVE,ok); } + void sendbufsize(int s) { set(SOL_SOCKET,SO_SNDBUF,s); } + void recvbufsize(int s) { set(SOL_SOCKET,SO_RCVBUF,s); } + + isocket* accept() throw(merror_t); + + int test() { return rd.poll(); } + int getsome(char* s,int n) { return rd.read(s,n); } + int gethead(char* s,int n) { return rd.readpara(s,n); } + int getbody(char* s,int n) { return rd.readx(s,n); } + +protected: + void setflag(int f) { fcntl(fd,F_SETFL,f); } + int getflag() const { return fcntl(fd,F_GETFL,0); } + void set(int lev,int opt,int ok) throw(merror_t) { + if(setsockopt(fd,lev,opt,(char*)&ok,sizeof(ok))<0) + THROW("isocket: Could not set option"); + } +private: + sockaddr_in sa; + mread rd; +}; + +#endif -- cgit v1.2.3