diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
| commit | 5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch) | |
| tree | 1a81af141708b826e9c61e8a04019994fcca8298 /src/net/isocket.h | |
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/net/isocket.h')
| -rw-r--r-- | src/net/isocket.h | 68 |
1 files changed, 68 insertions, 0 deletions
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 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifndef ISOCKETH | ||
| 21 | #define ISOCKETH | ||
| 22 | |||
| 23 | #include <mt/mread.h> | ||
| 24 | #include <mt/mstring.h> | ||
| 25 | #include <sys/socket.h> | ||
| 26 | #include <arpa/inet.h> | ||
| 27 | #include <netinet/in.h> | ||
| 28 | #include <netinet/tcp.h> | ||
| 29 | |||
| 30 | class isocket : public pipe_stream { | ||
| 31 | public: | ||
| 32 | isocket(const in_addr& ia,int port,int backlog); | ||
| 33 | isocket(int f,const sockaddr_in& ia); | ||
| 34 | ~isocket() { close(); } | ||
| 35 | |||
| 36 | void close() { if(fd>=0) { ::close(fd); fd=-1; }} | ||
| 37 | |||
| 38 | int getfd() const { return fd; } | ||
| 39 | int family() const { return sa.sin_family; } | ||
| 40 | int port() const { return ntohs(sa.sin_port); } | ||
| 41 | in_addr address() const { return sa.sin_addr; } | ||
| 42 | |||
| 43 | void reuse(int ok) { set(SOL_SOCKET,SO_REUSEADDR,ok); } | ||
| 44 | void nodelay(int ok) { set(IPPROTO_TCP,TCP_NODELAY,ok); } | ||
| 45 | void keepalive(int ok) { set(SOL_SOCKET,SO_KEEPALIVE,ok); } | ||
| 46 | void sendbufsize(int s) { set(SOL_SOCKET,SO_SNDBUF,s); } | ||
| 47 | void recvbufsize(int s) { set(SOL_SOCKET,SO_RCVBUF,s); } | ||
| 48 | |||
| 49 | isocket* accept() throw(merror_t); | ||
| 50 | |||
| 51 | int test() { return rd.poll(); } | ||
| 52 | int getsome(char* s,int n) { return rd.read(s,n); } | ||
| 53 | int gethead(char* s,int n) { return rd.readpara(s,n); } | ||
| 54 | int getbody(char* s,int n) { return rd.readx(s,n); } | ||
| 55 | |||
| 56 | protected: | ||
| 57 | void setflag(int f) { fcntl(fd,F_SETFL,f); } | ||
| 58 | int getflag() const { return fcntl(fd,F_GETFL,0); } | ||
| 59 | void set(int lev,int opt,int ok) throw(merror_t) { | ||
| 60 | if(setsockopt(fd,lev,opt,(char*)&ok,sizeof(ok))<0) | ||
| 61 | THROW("isocket: Could not set option"); | ||
| 62 | } | ||
| 63 | private: | ||
| 64 | sockaddr_in sa; | ||
| 65 | mread rd; | ||
| 66 | }; | ||
| 67 | |||
| 68 | #endif | ||
