libcommonc++  0.7
StreamSocket.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_StreamSocket_hxx
24 #define __ccxx_StreamSocket_hxx
25 
26 #include <commonc++/Common.h++>
28 #include <commonc++/Socket.h++>
29 #include <commonc++/Stream.h++>
30 
31 namespace ccxx {
32 
38 class COMMONCPP_API StreamSocket : public Stream, public Socket
39 {
40  friend class ServerSocket;
41 
42  public:
43 
50  StreamSocket(uint16_t port = 0);
51 
53  ~StreamSocket();
54 
55  void connect(const String& addr, uint16_t port);
56  void connect(const SocketAddress& addr);
57 
58  size_t read(byte_t* buffer, size_t buflen);
59  size_t write(const byte_t* buffer, size_t buflen);
60 
61  inline size_t read(ByteBuffer& buffer)
62  { return(Stream::read(buffer)); }
63 
64  inline size_t write(ByteBuffer& buffer)
65  { return(Stream::write(buffer)); }
66 
67  inline size_t read(CharBuffer& buffer)
68  { return(Stream::read(buffer)); }
69 
70  inline size_t write(CharBuffer& buffer)
71  { return(Stream::write(buffer)); }
72 
73  inline size_t read(byte_t* buffer, size_t buflen, int64_t offset,
74  AsyncIOTask& task)
75  { return(Stream::read(buffer, buflen, offset, task)); }
76 
77  inline size_t write(const byte_t* buffer, size_t buflen, int64_t offset,
78  AsyncIOTask& task)
79  { return(Stream::write(buffer, buflen, offset, task)); }
80 
81  inline size_t read(ByteBuffer& buffer, int64_t offset, AsyncIOTask& task)
82  { return(Stream::read(buffer, offset, task)); }
83 
84  inline size_t write(ByteBuffer& buffer, int64_t offset, AsyncIOTask& task)
85  { return(Stream::write(buffer, offset, task)); }
86 
87  size_t read(MemoryBlock* vec, uint_t count);
88  size_t write(const MemoryBlock* vec, uint_t count);
89 
96  byte_t readOOB();
97 
104  void writeOOB(byte_t data);
105 
106  void close(IOMode mode = IOReadWrite);
107  virtual void shutdown();
108 
109  void setTimeout(timespan_ms_t timeout);
110 
111  private:
112 
113  void setSocketHandle(SocketHandle handle);
114 
116 };
117 
118 } // namespace ccxx
119 
120 #endif // __ccxx_StreamSocket_hxx
size_t write(ByteBuffer &buffer)
Write data to the stream from a ByteBuffer.
Definition: StreamSocket.h++:64
IOMode
Stream I/O modes.
Definition: Stream.h++:36
An encapsulation of a block of memory.
Definition: MemoryBlock.h++:37
size_t read(byte_t *buffer, size_t buflen, int64_t offset, AsyncIOTask &task)
Definition: StreamSocket.h++:73
An unbuffered I/O stream.
Definition: Stream.h++:60
size_t read(ByteBuffer &buffer, int64_t offset, AsyncIOTask &task)
Definition: StreamSocket.h++:81
A server (listening) socket for StreamSocket (TCP) connections.
Definition: ServerSocket.h++:40
A reliable, connection-oriented stream (TCP) socket.
Definition: StreamSocket.h++:38
A base class for network sockets.
Definition: Socket.h++:61
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
size_t write(const byte_t *buffer, size_t buflen, int64_t offset, AsyncIOTask &task)
Write data asynchronously to the stream from a raw buffer.
Definition: Stream.c++:727
size_t write(ByteBuffer &buffer, int64_t offset, AsyncIOTask &task)
Definition: StreamSocket.h++:84
Read/write mode.
Definition: Stream.h++:42
int SocketHandle
Definition: Socket.h++:52
A socket endpoint network address.
Definition: SocketAddress.h++:46
size_t write(CharBuffer &buffer)
Write data to the stream from a CharBuffer.
Definition: StreamSocket.h++:70
virtual size_t read(ByteBuffer &buffer)
Read data from the stream into a ByteBuffer.
Definition: Stream.c++:93
#define COMMONCPP_API
Definition: Common.h++:126
A buffer for storing a contiguous sequence of elements.
Definition: Buffer.h++:44
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
size_t read(ByteBuffer &buffer)
Read data from the stream into a ByteBuffer.
Definition: StreamSocket.h++:61
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
size_t write(const byte_t *buffer, size_t buflen, int64_t offset, AsyncIOTask &task)
Definition: StreamSocket.h++:77
Definition: AllocationMap.c++:25
size_t read(CharBuffer &buffer)
Read data from the stream into a CharBuffer.
Definition: StreamSocket.h++:67
An object representing an asynchronous I/O operation.
Definition: AsyncIOTask.h++:43
unsigned char byte_t
An unsigned 8-bit value.
Definition: Integers.h++:68