29 #ifndef RGJ_FREE_STREAM_H_ 30 #define RGJ_FREE_STREAM_H_ 34 #include <skstream/sksocket.h> 48 std::streambuf::char_type *_buffer;
53 timeval _underflow_timeout;
54 timeval _overflow_timeout;
69 explicit socketbuf(SOCKET_TYPE sock, std::streamsize insize = 0x8000,
70 std::streamsize outsize = 0x8000);
74 socketbuf(SOCKET_TYPE sock, std::streambuf::char_type * buf,
75 std::streamsize length);
92 _underflow_timeout.tv_sec = sec;
93 _underflow_timeout.tv_usec = usec;
100 _overflow_timeout.tv_sec = sec;
101 _overflow_timeout.tv_usec = usec;
104 void setTimeout(
unsigned sec,
unsigned usec=0) {
115 virtual int_type
overflow(int_type nCh = traits_type::eof()) = 0;
125 std::streambuf *
setbuf(std::streambuf::char_type * buf, std::streamsize len);
135 std::streamsize insize = 0x8000,
136 std::streamsize outsize = 0x8000);
141 std::streamsize length);
148 virtual int_type
overflow(int_type nCh = traits_type::eof());
160 explicit dgram_socketbuf(SOCKET_TYPE sock, std::streamsize insize = 0x8000,
161 std::streamsize outsize = 0x8000);
166 std::streambuf::char_type * buf,
167 std::streamsize length);
172 bool setTarget(
const std::string& address,
unsigned port,
int proto);
174 void setOutpeer(
const sockaddr_storage & peer) {
178 const sockaddr_storage & getOutpeer()
const {
182 const sockaddr_storage & getInpeer()
const {
186 SOCKLEN getOutpeerSize()
const {
190 SOCKLEN getInpeerSize()
const {
205 virtual int_type
overflow(int_type nCh = traits_type::eof());
242 virtual void close();
244 void shutdown(
bool wr_only =
false);
250 void setTimeout(
unsigned sec,
unsigned usec=0) {
251 _sockbuf.setTimeout(sec,usec);
254 int getProtocol()
const {
269 SOCKET_TYPE _connecting_socket;
276 virtual void close();
279 bool connect_pending()
const {
280 return (_connecting_socket != INVALID_SOCKET);
297 struct addrinfo * _connecting_address;
298 struct addrinfo * _connecting_addrlist;
305 bool nonblock =
false);
308 unsigned int milliseconds);
312 int open(
const std::string& address,
int service,
bool nonblock =
false);
313 int open(
const std::string& address,
int service,
unsigned int milliseconds);
314 int open(
struct addrinfo *,
bool nonblock =
false);
317 const std::string getRemoteHost(
bool lookup =
false)
const;
318 const std::string getRemoteService(
bool lookup =
false)
const;
319 bool isReady(
unsigned int milliseconds = 0);
332 int bindToIpService(
int service,
int type,
int protocol);
339 bool setTarget(
const std::string& address,
unsigned port) {
340 return dgram_sockbuf.setTarget(address, port, m_protocol);
343 void setOutpeer(
const sockaddr_storage& peer) {
344 return dgram_sockbuf.setOutpeer(peer);
347 const sockaddr_storage & getOutpeer()
const {
348 return dgram_sockbuf.getOutpeer();
351 const sockaddr_storage & getInpeer()
const {
352 return dgram_sockbuf.getInpeer();
355 SOCKLEN getOutpeerSize()
const {
356 return dgram_sockbuf.getOutpeerSize();
359 SOCKLEN getInpeerSize()
const {
360 return dgram_sockbuf.getInpeerSize();
381 int open(
int service);
393 raw_socket_stream(
const raw_socket_stream&);
395 raw_socket_stream&
operator=(
const raw_socket_stream& socket);
398 raw_socket_stream(FreeSockets::IP_Protocol proto=FreeSockets::proto_RAW);
400 virtual ~raw_socket_stream();
402 void setProtocol(FreeSockets::IP_Protocol proto);
404 bool setTarget(
const std::string& address,
unsigned port) {
405 return dgram_sockbuf.setTarget(address, port, m_protocol);
408 bool setBroadcast(
bool opt=
false);
413 #endif // RGJ_FREE_STREAM_H_ An iostream class that handle TCP sockets.
Definition: skstream.h:291
virtual int_type overflow(int_type nCh=traits_type::eof())=0
Handle writing data from the buffer to the socket.
A stream buffer class that handles datagram sockets.
Definition: skstream.h:155
A base class for stream buffers that handle sockets.
Definition: skstream.h:46
SOCKLEN out_p_size
Size of target address.
Definition: skstream.h:200
std::streambuf * setbuf(std::streambuf::char_type *buf, std::streamsize len)
Definition: skstream.cpp:207
Definition: skstream.h:263
Base class for anything that encapsulates a socket.
Definition: sksocket.h:79
virtual int_type underflow()=0
Handle reading data from the socket to the buffer.
void setReadTimeout(unsigned sec, unsigned usec=0)
Definition: skstream.h:91
A base class for iostreams that handles stream sockets.
Definition: skstream.h:216
sockaddr_storage out_peer
Target address of datagrams sent via this stream.
Definition: skstream.h:196
void setSocket(SOCKET_TYPE sock)
Set the existing socket that this buffer should use.
Definition: skstream.cpp:187
An iostream class that handle IP datagram sockets.
Definition: skstream.h:323
socketbuf(const socketbuf &)
Not implemented. Copying a socket buffer is not permited.
socketbuf & operator=(const socketbuf &)
Not implemented. Copying a socket buffer is not permited.
SOCKET_TYPE getSocket() const
Get the socket that this buffer uses.
Definition: skstream.h:84
sockaddr_storage in_peer
Source address of last datagram received by this stream.
Definition: skstream.h:198
void setWriteTimeout(unsigned sec, unsigned usec=0)
Definition: skstream.h:99
bool timeout() const
Return the flag indicating whether a timeout has occured.
Definition: skstream.h:109
virtual int sync()
Flush the output buffer.
Definition: skstream.cpp:193
A stream buffer class that handles stream sockets.
Definition: skstream.h:129
SOCKLEN in_p_size
Size of source address.
Definition: skstream.h:202
An iostream class that handle UDP sockets.
Definition: skstream.h:370
virtual ~socketbuf()
Destroy the socket buffer.
Definition: skstream.cpp:179