Fixes (hopefully) for windows and other platforms...
This commit is contained in:
@@ -101,7 +101,7 @@ sockinetaddr::sockinetaddr (const sockinetaddr& sina)
|
||||
{
|
||||
sin_family = sockinetbuf::af_inet;
|
||||
sin_addr.s_addr = sina.sin_addr.s_addr;
|
||||
sin_port = sina.sin_port;
|
||||
sin_port = sina.sin_port;
|
||||
}
|
||||
|
||||
void sockinetaddr::setport(const char* sn, const char* pn)
|
||||
@@ -159,10 +159,7 @@ sockinetaddr sockinetbuf::localaddr() const
|
||||
{
|
||||
sockinetaddr sin;
|
||||
int len = sin.size();
|
||||
if (::getsockname(rep->sock, sin.addr (),
|
||||
#ifndef __sgi
|
||||
(socklen_t*) // LN
|
||||
#endif
|
||||
if (::getsockname(rep->sock, sin.addr (), (socklen_t*) // LN
|
||||
&len) == -1)
|
||||
throw sockerr (errno, "sockinetbuf::localaddr");
|
||||
return sin;
|
||||
@@ -186,10 +183,7 @@ sockinetaddr sockinetbuf::peeraddr() const
|
||||
{
|
||||
sockinetaddr sin;
|
||||
int len = sin.size();
|
||||
if (::getpeername(rep->sock, sin.addr (),
|
||||
#ifndef __sgi
|
||||
(socklen_t*) // LN
|
||||
#endif
|
||||
if (::getpeername(rep->sock, sin.addr (), (socklen_t*) // LN
|
||||
&len) == -1)
|
||||
throw sockerr (errno, "sockinetbuf::peeraddr");
|
||||
return sin;
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
// Version: 12Jan97 1.11
|
||||
|
||||
#ifndef _SOCKINET_H
|
||||
#define _SOCKINET_H
|
||||
#define _SOCKINET_H
|
||||
|
||||
#include "sockstream.h"
|
||||
#ifndef WIN32
|
||||
# include <netinet/in.h>
|
||||
# include <netinet/in.h>
|
||||
#endif // !WIN32
|
||||
|
||||
class sockinetaddr: public sockAddr, public sockaddr_in
|
||||
@@ -46,82 +46,81 @@ class sockinetaddr: public sockAddr, public sockaddr_in
|
||||
const char* gethostname() const;
|
||||
};
|
||||
|
||||
class sockinetbuf: public sockbuf {
|
||||
public:
|
||||
enum domain { af_inet = AF_INET };
|
||||
class sockinetbuf: public sockbuf
|
||||
{
|
||||
public:
|
||||
enum domain { af_inet = AF_INET };
|
||||
|
||||
sockinetbuf (const sockbuf::sockdesc& sd);
|
||||
sockinetbuf (const sockinetbuf& si): sockbuf (si) {}
|
||||
sockinetbuf (sockbuf::type ty, int proto=0);
|
||||
sockinetbuf& operator=(const sockinetbuf& si);
|
||||
~sockinetbuf () {}
|
||||
sockinetbuf (const sockbuf::sockdesc& sd);
|
||||
sockinetbuf (const sockinetbuf& si): sockbuf (si) {}
|
||||
sockinetbuf (sockbuf::type ty, int proto=0);
|
||||
sockinetbuf& operator=(const sockinetbuf& si);
|
||||
~sockinetbuf () {}
|
||||
|
||||
sockinetaddr localaddr() const;
|
||||
int localport() const;
|
||||
const char* localhost() const;
|
||||
sockinetaddr localaddr() const;
|
||||
int localport() const;
|
||||
const char* localhost() const;
|
||||
|
||||
sockinetaddr peeraddr() const;
|
||||
int peerport() const;
|
||||
const char* peerhost() const;
|
||||
sockinetaddr peeraddr() const;
|
||||
int peerport() const;
|
||||
const char* peerhost() const;
|
||||
|
||||
void bind_until_success (int portno);
|
||||
void bind_until_success (int portno);
|
||||
|
||||
virtual void bind (sockAddr& sa);
|
||||
void bind (int port_no=0); // addr is assumed to be INADDR_ANY
|
||||
// and thus defaults to local host
|
||||
virtual void bind (sockAddr& sa);
|
||||
void bind (int port_no=0); // addr is assumed to be INADDR_ANY
|
||||
// and thus defaults to local host
|
||||
|
||||
void bind (unsigned long addr, int port_no);
|
||||
void bind (const char* host_name, int port_no=0);
|
||||
void bind (unsigned long addr,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
void bind (const char* host_name,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
void bind (unsigned long addr, int port_no);
|
||||
void bind (const char* host_name, int port_no=0);
|
||||
void bind (unsigned long addr,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
void bind (const char* host_name,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
|
||||
virtual void connect (sockAddr& sa);
|
||||
void connect (unsigned long addr, int port_no);
|
||||
void connect (const char* host_name, int port_no);
|
||||
void connect (unsigned long addr,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
void connect (const char* host_name,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
virtual void connect (sockAddr& sa);
|
||||
void connect (unsigned long addr, int port_no);
|
||||
void connect (const char* host_name, int port_no);
|
||||
void connect (unsigned long addr,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
void connect (const char* host_name,
|
||||
const char* service_name,
|
||||
const char* protocol_name="tcp");
|
||||
|
||||
virtual sockdesc accept ();
|
||||
virtual sockdesc accept (sockAddr& sa);
|
||||
sockdesc accept (unsigned long addr, int port_no);
|
||||
sockdesc accept (const char* host_name, int port_no);
|
||||
virtual sockdesc accept ();
|
||||
virtual sockdesc accept (sockAddr& sa);
|
||||
sockdesc accept (unsigned long addr, int port_no);
|
||||
sockdesc accept (const char* host_name, int port_no);
|
||||
|
||||
bool tcpnodelay () const;
|
||||
bool tcpnodelay (bool set) const;
|
||||
bool tcpnodelay () const;
|
||||
bool tcpnodelay (bool set) const;
|
||||
};
|
||||
|
||||
class isockinet: public isockstream
|
||||
{
|
||||
public:
|
||||
isockinet (const sockbuf::sockdesc& sd);
|
||||
isockinet (const sockinetbuf& sb);
|
||||
isockinet (sockbuf::type ty=sockbuf::sock_stream,
|
||||
int proto=0);
|
||||
~isockinet ();
|
||||
public:
|
||||
isockinet (const sockbuf::sockdesc& sd);
|
||||
isockinet (const sockinetbuf& sb);
|
||||
isockinet (sockbuf::type ty=sockbuf::sock_stream, int proto=0);
|
||||
~isockinet ();
|
||||
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
class osockinet: public osockstream
|
||||
{
|
||||
public:
|
||||
osockinet (const sockbuf::sockdesc& sd);
|
||||
osockinet (const sockinetbuf& sb);
|
||||
osockinet (sockbuf::type ty=sockbuf::sock_stream,
|
||||
int proto=0);
|
||||
~osockinet ();
|
||||
public:
|
||||
osockinet (const sockbuf::sockdesc& sd);
|
||||
osockinet (const sockinetbuf& sb);
|
||||
osockinet (sockbuf::type ty=sockbuf::sock_stream, int proto=0);
|
||||
~osockinet ();
|
||||
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
class iosockinet: public iosockstream
|
||||
@@ -129,12 +128,11 @@ class iosockinet: public iosockstream
|
||||
public:
|
||||
iosockinet (const sockbuf::sockdesc& sd);
|
||||
iosockinet (const sockinetbuf& sb);
|
||||
iosockinet (sockbuf::type ty=sockbuf::sock_stream,
|
||||
int proto=0);
|
||||
iosockinet (sockbuf::type ty=sockbuf::sock_stream, int proto=0);
|
||||
~iosockinet ();
|
||||
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
|
||||
sockinetbuf* operator -> () { return rdbuf (); }
|
||||
};
|
||||
|
||||
#endif // _SOCKINET_H
|
||||
|
||||
@@ -135,9 +135,7 @@ extern "C" {
|
||||
const char* sockerr::errstr () const
|
||||
{
|
||||
#ifndef WIN32
|
||||
//extern char *sys_errlist;
|
||||
return sys_errlist[err];
|
||||
//return SYS_ERRLIST [err];
|
||||
#else
|
||||
return 0; // TODO
|
||||
#endif
|
||||
@@ -265,6 +263,11 @@ sockbuf::sockbuf (const sockbuf::sockdesc& sd)
|
||||
sockbuf::sockbuf (int domain, sockbuf::type st, int proto)
|
||||
: rep (0)
|
||||
{
|
||||
#ifdef WIN32
|
||||
WORD version = MAKEWORD(1,1);
|
||||
WSADATA wsaData;
|
||||
WSAStartup(version, &wsaData);
|
||||
#endif
|
||||
SOCKET soc = ::socket (domain, st, proto);
|
||||
|
||||
if (soc == SOCKET_ERROR)
|
||||
@@ -493,10 +496,7 @@ sockbuf::sockdesc sockbuf::accept (sockAddr& sa)
|
||||
{
|
||||
int len = sa.size ();
|
||||
int soc = -1;
|
||||
if ((soc = ::accept (rep->sock, sa.addr (),
|
||||
#ifndef __sgi
|
||||
(socklen_t*) // LN
|
||||
#endif
|
||||
if ((soc = ::accept (rep->sock, sa.addr (), (socklen_t*) // LN
|
||||
&len)) == -1)
|
||||
throw sockerr (errno, "sockbuf::sockdesc", sockname.c_str());
|
||||
return sockdesc (soc);
|
||||
@@ -520,7 +520,8 @@ int sockbuf::read (void* buf, int len)
|
||||
throw sockoob ();
|
||||
|
||||
int rval = 0;
|
||||
if ((rval = ::read (rep->sock, (char*) buf, len)) == -1)
|
||||
//if ((rval = ::read (rep->sock, (char*) buf, len)) == -1)
|
||||
if ((rval = ::recv (rep->sock, (char*) buf, len, 0)) == -1)
|
||||
throw sockerr (errno, "sockbuf::read", sockname.c_str());
|
||||
return rval;
|
||||
}
|
||||
@@ -551,10 +552,7 @@ int sockbuf::recvfrom (sockAddr& sa, void* buf, int len, int msgf)
|
||||
int __sa_len = sa.size ();
|
||||
|
||||
if ((rval = ::recvfrom (rep->sock, (char*) buf, len,
|
||||
msgf, sa.addr (),
|
||||
#ifndef __sgi
|
||||
(socklen_t*) // LN
|
||||
#endif
|
||||
msgf, sa.addr (), (socklen_t*) // LN
|
||||
&__sa_len)) == -1)
|
||||
throw sockerr (errno, "sockbuf::recvfrom", sockname.c_str());
|
||||
return rval;
|
||||
@@ -569,7 +567,8 @@ int sockbuf::write(const void* buf, int len)
|
||||
|
||||
int wlen=0;
|
||||
while(len>0) {
|
||||
int wval = ::write (rep->sock, (char*) buf, len);
|
||||
//int wval = ::write (rep->sock, (char*) buf, len);
|
||||
int wval = ::send (rep->sock, (char*) buf, len, 0);
|
||||
if (wval == -1) throw wlen;
|
||||
len -= wval;
|
||||
wlen += wval;
|
||||
@@ -721,10 +720,7 @@ void sockbuf::shutdown (shuthow sh)
|
||||
|
||||
int sockbuf::getopt (int op, void* buf, int len, int level) const
|
||||
{
|
||||
if (::getsockopt (rep->sock, level, op, (char*) buf,
|
||||
#ifndef __sgi
|
||||
(socklen_t*) // LN
|
||||
#endif
|
||||
if (::getsockopt (rep->sock, level, op, (char*) buf, (socklen_t*) // LN
|
||||
&len) == -1)
|
||||
throw sockerr (errno, "sockbuf::getopt", sockname.c_str());
|
||||
return len;
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
// Version: 12Jan97 1.11
|
||||
//
|
||||
// Version: 1.2 2002-07-25 Herbert Straub
|
||||
// Improved Error Handling - extending the sockerr class by cOperation
|
||||
// Improved Error Handling - extending the sockerr class by cOperation
|
||||
// 2003-03-06 Herbert Straub
|
||||
// adding sockbuf::getname und setname (sockname)
|
||||
// sockbuf methods throw method name + sockname
|
||||
// adding sockbuf::getname und setname (sockname)
|
||||
// sockbuf methods throw method name + sockname
|
||||
|
||||
#ifndef _SOCKSTREAM_H
|
||||
#define _SOCKSTREAM_H
|
||||
#define _SOCKSTREAM_H
|
||||
|
||||
#include <iostream> // must be ANSI compatible
|
||||
//#include <cstddef>
|
||||
@@ -41,305 +41,320 @@
|
||||
#include <string>
|
||||
//#include <cstdio>
|
||||
#ifndef WIN32
|
||||
# include <sys/types.h>
|
||||
# include <sys/uio.h>
|
||||
# include <sys/socket.h>
|
||||
# define SOCKET int
|
||||
# define SOCKET_ERROR -1
|
||||
# include <sys/types.h>
|
||||
# include <sys/uio.h>
|
||||
# include <sys/socket.h>
|
||||
# define SOCKET int
|
||||
# define SOCKET_ERROR -1
|
||||
#else
|
||||
# include <Wininet.h>
|
||||
# pragma comment(lib, "Wininet")
|
||||
# include <windows.h>
|
||||
# include <Wininet.h>
|
||||
# pragma comment(lib, "Wininet")
|
||||
#endif
|
||||
|
||||
#ifdef __sgi
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef __linux__
|
||||
# define MSG_MAXIOVLEN 16
|
||||
# define MSG_MAXIOVLEN 16
|
||||
#endif // __linux__
|
||||
|
||||
// socket exception classes
|
||||
class sockerr {
|
||||
int err;
|
||||
string text;
|
||||
public:
|
||||
sockerr (int e, const char *operation = NULL): err (e) {
|
||||
if (operation != NULL) {
|
||||
text = operation;
|
||||
}
|
||||
}
|
||||
sockerr (int e, const char *operation, const char *specification) : err (e) {
|
||||
if (operation != NULL)
|
||||
text = operation;
|
||||
if (specification != NULL) {
|
||||
text += "(";
|
||||
text += specification;
|
||||
text += ")";
|
||||
}
|
||||
}
|
||||
sockerr (int e, const string &operation): err (e) {
|
||||
text = operation;
|
||||
}
|
||||
sockerr (const sockerr &O) {
|
||||
err = O.err;
|
||||
text = O.text;
|
||||
}
|
||||
class sockerr
|
||||
{
|
||||
int err;
|
||||
string text;
|
||||
public:
|
||||
sockerr (int e, const char *operation = NULL): err (e)
|
||||
{
|
||||
if (operation != NULL)
|
||||
{
|
||||
text = operation;
|
||||
}
|
||||
}
|
||||
sockerr (int e, const char *operation, const char *specification) : err (e)
|
||||
{
|
||||
if (operation != NULL)
|
||||
text = operation;
|
||||
if (specification != NULL)
|
||||
{
|
||||
text += "(";
|
||||
text += specification;
|
||||
text += ")";
|
||||
}
|
||||
}
|
||||
sockerr (int e, const string &operation): err (e)
|
||||
{
|
||||
text = operation;
|
||||
}
|
||||
sockerr (const sockerr &O)
|
||||
{
|
||||
err = O.err;
|
||||
text = O.text;
|
||||
}
|
||||
|
||||
const char* what () const { return "sockerr"; }
|
||||
const char* operation () const { return text.c_str(); }
|
||||
const char* what () const { return "sockerr"; }
|
||||
const char* operation () const { return text.c_str(); }
|
||||
|
||||
// int errno () const { return err; }
|
||||
int serrno () const { return err; } // LN
|
||||
const char* errstr () const;
|
||||
bool error (int eno) const { return eno == err; }
|
||||
// int errno () const { return err; }
|
||||
int serrno () const { return err; } // LN
|
||||
const char* errstr () const;
|
||||
bool error (int eno) const { return eno == err; }
|
||||
|
||||
bool io () const; // non-blocking and interrupt io recoverable error.
|
||||
bool arg () const; // incorrect argument supplied. recoverable error.
|
||||
bool op () const; // operational error. recovery difficult.
|
||||
bool io () const; // non-blocking and interrupt io recoverable error.
|
||||
bool arg () const; // incorrect argument supplied. recoverable error.
|
||||
bool op () const; // operational error. recovery difficult.
|
||||
|
||||
bool conn () const; // connection error
|
||||
bool addr () const; // address error
|
||||
bool benign () const; // recoverable read/write error like EINTR etc.
|
||||
bool conn () const; // connection error
|
||||
bool addr () const; // address error
|
||||
bool benign () const; // recoverable read/write error like EINTR etc.
|
||||
};
|
||||
|
||||
class sockoob {
|
||||
public:
|
||||
const char* what () const { return "sockoob"; }
|
||||
class sockoob
|
||||
{
|
||||
public:
|
||||
const char* what () const { return "sockoob"; }
|
||||
};
|
||||
|
||||
// socket address classes
|
||||
struct sockaddr;
|
||||
|
||||
class sockAddr {
|
||||
public:
|
||||
virtual ~sockAddr() {}
|
||||
|
||||
virtual operator void* () const =0;
|
||||
operator sockaddr* () const { return addr (); }
|
||||
virtual int size () const =0;
|
||||
virtual int family () const =0;
|
||||
virtual sockaddr* addr () const =0;
|
||||
class sockAddr
|
||||
{
|
||||
public:
|
||||
virtual ~sockAddr() {}
|
||||
virtual operator void* () const =0;
|
||||
operator sockaddr* () const { return addr (); }
|
||||
virtual int size() const =0;
|
||||
virtual int family() const =0;
|
||||
virtual sockaddr* addr () const =0;
|
||||
};
|
||||
|
||||
struct msghdr;
|
||||
|
||||
// socket buffer class
|
||||
class sockbuf: public streambuf {
|
||||
public:
|
||||
enum type {
|
||||
sock_stream = SOCK_STREAM,
|
||||
sock_dgram = SOCK_DGRAM,
|
||||
sock_raw = SOCK_RAW,
|
||||
sock_rdm = SOCK_RDM,
|
||||
sock_seqpacket = SOCK_SEQPACKET
|
||||
};
|
||||
enum option {
|
||||
so_debug = SO_DEBUG,
|
||||
so_reuseaddr = SO_REUSEADDR,
|
||||
so_keepalive = SO_KEEPALIVE,
|
||||
so_dontroute = SO_DONTROUTE,
|
||||
so_broadcast = SO_BROADCAST,
|
||||
so_linger = SO_LINGER,
|
||||
so_oobinline = SO_OOBINLINE,
|
||||
so_sndbuf = SO_SNDBUF,
|
||||
so_rcvbuf = SO_RCVBUF,
|
||||
so_error = SO_ERROR,
|
||||
so_type = SO_TYPE
|
||||
};
|
||||
enum level {
|
||||
sol_socket = SOL_SOCKET
|
||||
};
|
||||
enum msgflag {
|
||||
msg_oob = MSG_OOB,
|
||||
msg_peek = MSG_PEEK,
|
||||
msg_dontroute = MSG_DONTROUTE,
|
||||
class sockbuf: public streambuf
|
||||
{
|
||||
public:
|
||||
enum type {
|
||||
sock_stream = SOCK_STREAM,
|
||||
sock_dgram = SOCK_DGRAM,
|
||||
sock_raw = SOCK_RAW,
|
||||
sock_rdm = SOCK_RDM,
|
||||
sock_seqpacket = SOCK_SEQPACKET
|
||||
};
|
||||
enum option {
|
||||
so_debug = SO_DEBUG,
|
||||
so_reuseaddr = SO_REUSEADDR,
|
||||
so_keepalive = SO_KEEPALIVE,
|
||||
so_dontroute = SO_DONTROUTE,
|
||||
so_broadcast = SO_BROADCAST,
|
||||
so_linger = SO_LINGER,
|
||||
so_oobinline = SO_OOBINLINE,
|
||||
so_sndbuf = SO_SNDBUF,
|
||||
so_rcvbuf = SO_RCVBUF,
|
||||
so_error = SO_ERROR,
|
||||
so_type = SO_TYPE
|
||||
};
|
||||
enum level {
|
||||
sol_socket = SOL_SOCKET
|
||||
};
|
||||
enum msgflag {
|
||||
msg_oob = MSG_OOB,
|
||||
msg_peek = MSG_PEEK,
|
||||
msg_dontroute = MSG_DONTROUTE,
|
||||
|
||||
#if !(defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__APPLE__))
|
||||
msg_maxiovlen = MSG_MAXIOVLEN
|
||||
msg_maxiovlen = MSG_MAXIOVLEN
|
||||
#endif
|
||||
};
|
||||
enum shuthow {
|
||||
shut_read,
|
||||
shut_write,
|
||||
shut_readwrite
|
||||
};
|
||||
enum { somaxconn = SOMAXCONN };
|
||||
struct socklinger {
|
||||
int l_onoff; // option on/off
|
||||
int l_linger; // linger time
|
||||
};
|
||||
enum shuthow {
|
||||
shut_read,
|
||||
shut_write,
|
||||
shut_readwrite
|
||||
};
|
||||
enum { somaxconn = SOMAXCONN };
|
||||
struct socklinger {
|
||||
int l_onoff; // option on/off
|
||||
int l_linger; // linger time
|
||||
|
||||
socklinger (int a, int b): l_onoff (a), l_linger (b) {}
|
||||
};
|
||||
socklinger (int a, int b): l_onoff (a), l_linger (b) {}
|
||||
};
|
||||
|
||||
typedef char char_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
typedef int int_type;
|
||||
typedef int seekdir;
|
||||
// const int_type eof = EOF;
|
||||
enum { eof = EOF }; // LN
|
||||
typedef char char_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
typedef int int_type;
|
||||
typedef int seekdir;
|
||||
// const int_type eof = EOF;
|
||||
enum { eof = EOF }; // LN
|
||||
|
||||
struct sockdesc {
|
||||
int sock;
|
||||
sockdesc (int d): sock (d) {}
|
||||
};
|
||||
struct sockdesc {
|
||||
int sock;
|
||||
sockdesc (int d): sock (d) {}
|
||||
};
|
||||
|
||||
protected:
|
||||
struct sockcnt {
|
||||
SOCKET sock;
|
||||
int cnt;
|
||||
int stmo; // -1==block, 0==poll, >0 == waiting time in secs
|
||||
int rtmo; // -1==block, 0==poll, >0 == waiting time in secs
|
||||
bool oob; // check for out-of-band byte while reading
|
||||
void* gend; // end of input buffer
|
||||
void* pend; // end of output buffer
|
||||
protected:
|
||||
struct sockcnt {
|
||||
SOCKET sock;
|
||||
int cnt;
|
||||
int stmo; // -1==block, 0==poll, >0 == waiting time in secs
|
||||
int rtmo; // -1==block, 0==poll, >0 == waiting time in secs
|
||||
bool oob; // check for out-of-band byte while reading
|
||||
void* gend; // end of input buffer
|
||||
void* pend; // end of output buffer
|
||||
|
||||
sockcnt(SOCKET s)
|
||||
: sock(s), cnt(1), stmo (-1), rtmo (-1), oob (false),
|
||||
gend (0), pend (0) {}
|
||||
};
|
||||
sockcnt(SOCKET s):
|
||||
sock(s), cnt(1), stmo (-1), rtmo (-1), oob (false),
|
||||
gend (0), pend (0) {}
|
||||
};
|
||||
|
||||
sockcnt* rep; // counts the # refs to sock
|
||||
string sockname; // name of sockbuf - Herbert Straub
|
||||
sockcnt* rep; // counts the # refs to sock
|
||||
string sockname; // name of sockbuf - Herbert Straub
|
||||
|
||||
#if 0
|
||||
virtual sockbuf* setbuf (char_type* s, int_type* n);
|
||||
virtual pos_type seekoff (off_type off,
|
||||
seekdir way,
|
||||
ios::openmode which = ios::in|ios::out);
|
||||
virtual pos_type seekpos (pos_type sp,
|
||||
ios::openmode which = ios::in|ios::out);
|
||||
virtual sockbuf* setbuf (char_type* s, int_type* n);
|
||||
virtual pos_type seekoff (off_type off,
|
||||
seekdir way,
|
||||
ios::openmode which = ios::in|ios::out);
|
||||
virtual pos_type seekpos (pos_type sp,
|
||||
ios::openmode which = ios::in|ios::out);
|
||||
#endif
|
||||
|
||||
virtual int sync ();
|
||||
virtual int sync ();
|
||||
|
||||
virtual int showmanyc () const;
|
||||
virtual streamsize xsgetn (char_type* s, streamsize n);
|
||||
virtual int_type underflow ();
|
||||
virtual int_type uflow ();
|
||||
virtual int showmanyc () const;
|
||||
virtual streamsize xsgetn (char_type* s, streamsize n);
|
||||
virtual int_type underflow ();
|
||||
virtual int_type uflow ();
|
||||
|
||||
virtual int_type pbackfail (int_type c = eof);
|
||||
virtual int_type pbackfail (int_type c = eof);
|
||||
|
||||
virtual streamsize xsputn (const char_type* s, streamsize n);
|
||||
virtual int_type overflow (int_type c = eof);
|
||||
virtual streamsize xsputn (const char_type* s, streamsize n);
|
||||
virtual int_type overflow (int_type c = eof);
|
||||
|
||||
public:
|
||||
sockbuf (const sockdesc& sd);
|
||||
sockbuf (int domain, type, int proto);
|
||||
sockbuf (const sockbuf&);
|
||||
// sockbuf& operator = (const sockbuf&);
|
||||
virtual ~sockbuf ();
|
||||
public:
|
||||
sockbuf (const sockdesc& sd);
|
||||
sockbuf (int domain, type, int proto);
|
||||
sockbuf (const sockbuf&);
|
||||
// sockbuf& operator = (const sockbuf&);
|
||||
virtual ~sockbuf ();
|
||||
|
||||
int sd () const { return rep->sock; }
|
||||
int pubsync () { return sync (); }
|
||||
virtual bool is_open () const;
|
||||
int sd () const { return rep->sock; }
|
||||
int pubsync () { return sync (); }
|
||||
virtual bool is_open () const;
|
||||
|
||||
virtual void bind (sockAddr&);
|
||||
virtual void connect (sockAddr&);
|
||||
virtual void bind (sockAddr&);
|
||||
virtual void connect (sockAddr&);
|
||||
|
||||
void listen (int num=somaxconn);
|
||||
virtual sockdesc accept ();
|
||||
virtual sockdesc accept (sockAddr& sa);
|
||||
void listen (int num=somaxconn);
|
||||
virtual sockdesc accept();
|
||||
virtual sockdesc accept(sockAddr& sa);
|
||||
|
||||
int read (void* buf, int len);
|
||||
int recv (void* buf, int len, int msgf=0);
|
||||
int recvfrom(sockAddr& sa,
|
||||
void* buf, int len, int msgf=0);
|
||||
int read(void* buf, int len);
|
||||
int recv (void* buf, int len, int msgf=0);
|
||||
int recvfrom(sockAddr& sa, void* buf, int len, int msgf=0);
|
||||
|
||||
#if !defined(__linux__) && !defined(WIN32)
|
||||
int recvmsg (msghdr* msg, int msgf=0);
|
||||
int sendmsg (msghdr* msg, int msgf=0);
|
||||
#if !defined(__linux__) && !defined(WIN32)
|
||||
int recvmsg(msghdr* msg, int msgf=0);
|
||||
int sendmsg(msghdr* msg, int msgf=0);
|
||||
#endif
|
||||
|
||||
int write (const void* buf, int len);
|
||||
int send (const void* buf, int len, int msgf=0);
|
||||
int sendto (sockAddr& sa,
|
||||
const void* buf, int len, int msgf=0);
|
||||
int write(const void* buf, int len);
|
||||
int send(const void* buf, int len, int msgf=0);
|
||||
int sendto (sockAddr& sa, const void* buf, int len, int msgf=0);
|
||||
|
||||
int sendtimeout (int wp=-1);
|
||||
int recvtimeout (int wp=-1);
|
||||
int is_readready (int wp_sec, int wp_usec=0) const;
|
||||
int is_writeready (int wp_sec, int wp_usec=0) const;
|
||||
int is_exceptionpending (int wp_sec, int wp_usec=0) const;
|
||||
int sendtimeout (int wp=-1);
|
||||
int recvtimeout (int wp=-1);
|
||||
int is_readready (int wp_sec, int wp_usec=0) const;
|
||||
int is_writeready (int wp_sec, int wp_usec=0) const;
|
||||
int is_exceptionpending (int wp_sec, int wp_usec=0) const;
|
||||
|
||||
void shutdown (shuthow sh);
|
||||
void shutdown (shuthow sh);
|
||||
|
||||
int getopt(int op, void* buf, int len,
|
||||
int level=sol_socket) const;
|
||||
void setopt(int op, void* buf, int len,
|
||||
int level=sol_socket) const;
|
||||
int getopt(int op, void* buf, int len,
|
||||
int level=sol_socket) const;
|
||||
void setopt(int op, void* buf, int len,
|
||||
int level=sol_socket) const;
|
||||
|
||||
type gettype () const;
|
||||
int clearerror () const;
|
||||
bool debug () const;
|
||||
bool debug (bool set) const;
|
||||
bool reuseaddr () const;
|
||||
bool reuseaddr (bool set) const;
|
||||
bool keepalive () const;
|
||||
bool keepalive (bool set) const;
|
||||
bool dontroute () const;
|
||||
bool dontroute (bool set) const;
|
||||
bool broadcast () const;
|
||||
bool broadcast (bool set) const;
|
||||
bool oobinline () const;
|
||||
bool oobinline (bool set) const;
|
||||
bool oob () const { return rep->oob; }
|
||||
bool oob (bool b);
|
||||
int sendbufsz () const;
|
||||
int sendbufsz (int sz) const;
|
||||
int recvbufsz () const;
|
||||
int recvbufsz (int sz) const;
|
||||
socklinger linger () const;
|
||||
socklinger linger (socklinger opt) const;
|
||||
socklinger linger (int onoff, int tm) const
|
||||
{ return linger (socklinger (onoff, tm)); }
|
||||
type gettype () const;
|
||||
int clearerror () const;
|
||||
bool debug () const;
|
||||
bool debug (bool set) const;
|
||||
bool reuseaddr () const;
|
||||
bool reuseaddr (bool set) const;
|
||||
bool keepalive () const;
|
||||
bool keepalive (bool set) const;
|
||||
bool dontroute () const;
|
||||
bool dontroute (bool set) const;
|
||||
bool broadcast () const;
|
||||
bool broadcast (bool set) const;
|
||||
bool oobinline () const;
|
||||
bool oobinline (bool set) const;
|
||||
bool oob () const { return rep->oob; }
|
||||
bool oob (bool b);
|
||||
int sendbufsz () const;
|
||||
int sendbufsz (int sz) const;
|
||||
int recvbufsz () const;
|
||||
int recvbufsz (int sz) const;
|
||||
socklinger linger() const;
|
||||
socklinger linger(socklinger opt) const;
|
||||
socklinger linger(int onoff, int tm) const
|
||||
{ return linger (socklinger (onoff, tm)); }
|
||||
|
||||
bool atmark () const;
|
||||
long nread () const;
|
||||
long howmanyc () const;
|
||||
void nbio (bool set=true) const;
|
||||
inline void setname (const char *name);
|
||||
inline void setname (const string &name);
|
||||
inline const string& getname ();
|
||||
bool atmark() const;
|
||||
long nread() const;
|
||||
long howmanyc() const;
|
||||
void nbio(bool set=true) const;
|
||||
inline void setname(const char *name);
|
||||
inline void setname(const string &name);
|
||||
inline const string& getname();
|
||||
|
||||
#ifndef WIN32
|
||||
void async (bool set=true) const;
|
||||
int pgrp () const;
|
||||
int pgrp (int new_pgrp) const;
|
||||
void closeonexec (bool set=true) const;
|
||||
void async(bool set=true) const;
|
||||
int pgrp() const;
|
||||
int pgrp(int new_pgrp) const;
|
||||
void closeonexec(bool set=true) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
class isockstream: public istream {
|
||||
protected:
|
||||
// isockstream (): istream(rdbuf()), ios (0) {}
|
||||
public:
|
||||
isockstream(sockbuf* sb): istream(sb), ios (sb) {}
|
||||
virtual ~isockstream () {}
|
||||
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
class isockstream: public istream
|
||||
{
|
||||
protected:
|
||||
//isockstream (): istream(rdbuf()), ios (0) {}
|
||||
|
||||
public:
|
||||
isockstream(sockbuf* sb): istream(sb), ios (sb) {}
|
||||
virtual ~isockstream () {}
|
||||
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
};
|
||||
|
||||
class osockstream: public ostream {
|
||||
protected:
|
||||
// osockstream (): ostream(static_cast<>rdbuf()), ios (0) {}
|
||||
public:
|
||||
osockstream(sockbuf* sb): ostream(sb), ios (sb) {}
|
||||
virtual ~osockstream () {}
|
||||
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
class osockstream: public ostream
|
||||
{
|
||||
protected:
|
||||
//osockstream (): ostream(static_cast<>rdbuf()), ios (0) {}
|
||||
public:
|
||||
osockstream(sockbuf* sb): ostream(sb), ios (sb) {}
|
||||
virtual ~osockstream () {}
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
};
|
||||
|
||||
class iosockstream: public iostream {
|
||||
protected:
|
||||
iosockstream ();
|
||||
public:
|
||||
iosockstream(sockbuf* sb): iostream(sb), ios (sb) {}
|
||||
virtual ~iosockstream () {}
|
||||
class iosockstream: public iostream
|
||||
{
|
||||
protected:
|
||||
iosockstream ();
|
||||
public:
|
||||
iosockstream(sockbuf* sb): iostream(sb), ios (sb) {}
|
||||
virtual ~iosockstream () {}
|
||||
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
sockbuf* rdbuf () { return (sockbuf*)ios::rdbuf(); }
|
||||
sockbuf* operator -> () { return rdbuf(); }
|
||||
};
|
||||
|
||||
// manipulators
|
||||
@@ -350,15 +365,17 @@ extern osockstream& lfcr (osockstream&);
|
||||
|
||||
void sockbuf::setname (const char *name)
|
||||
{
|
||||
sockname = name;
|
||||
}
|
||||
void sockbuf::setname (const string &name)
|
||||
{
|
||||
sockname = name;
|
||||
}
|
||||
const string& sockbuf::getname ()
|
||||
{
|
||||
return sockname;
|
||||
sockname = name;
|
||||
}
|
||||
|
||||
#endif // _SOCKSTREAM_H
|
||||
void sockbuf::setname (const string &name)
|
||||
{
|
||||
sockname = name;
|
||||
}
|
||||
|
||||
const string& sockbuf::getname ()
|
||||
{
|
||||
return sockname;
|
||||
}
|
||||
|
||||
#endif // _SOCKSTREAM_H
|
||||
|
||||
Reference in New Issue
Block a user