source: XMLIO_V2/external/include/Poco/Net/StreamSocket.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1//
2// StreamSocket.h
3//
4// $Id: //poco/1.3/Net/include/Poco/Net/StreamSocket.h#4 $
5//
6// Library: Net
7// Package: Sockets
8// Module:  StreamSocket
9//
10// Definition of the StreamSocket class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Net_StreamSocket_INCLUDED
40#define Net_StreamSocket_INCLUDED
41
42
43#include "Poco/Net/Net.h"
44#include "Poco/Net/Socket.h"
45
46
47namespace Poco {
48namespace Net {
49
50
51class StreamSocketImpl;
52
53
54class Net_API StreamSocket: public Socket
55        /// This class provides an interface to a
56        /// TCP stream socket.
57{
58public:
59        StreamSocket();
60                /// Creates an unconnected stream socket.
61                ///
62                /// Before sending or receiving data, the socket
63                /// must be connected with a call to connect().
64
65        explicit StreamSocket(const SocketAddress& address);
66                /// Creates a stream socket and connects it to
67                /// the socket specified by address.
68
69        explicit StreamSocket(IPAddress::Family family);
70                /// Creates an unconnected stream socket
71                /// for the given address family.
72                ///
73                /// This is useful if certain socket options
74                /// (like send and receive buffer) sizes, that must
75                /// be set before connecting the socket, will be
76                /// set later on.
77
78        StreamSocket(const Socket& socket);
79                /// Creates the StreamSocket with the SocketImpl
80                /// from another socket. The SocketImpl must be
81                /// a StreamSocketImpl, otherwise an InvalidArgumentException
82                /// will be thrown.
83
84        virtual ~StreamSocket();
85                /// Destroys the StreamSocket.
86
87        StreamSocket& operator = (const Socket& socket);
88                /// Assignment operator.
89                ///
90                /// Releases the socket's SocketImpl and
91                /// attaches the SocketImpl from the other socket and
92                /// increments the reference count of the SocketImpl.   
93
94        void connect(const SocketAddress& address);
95                /// Initializes the socket and establishes a connection to
96                /// the TCP server at the given address.
97                ///
98                /// Can also be used for UDP sockets. In this case, no
99                /// connection is established. Instead, incoming and outgoing
100                /// packets are restricted to the specified address.
101
102        void connect(const SocketAddress& address, const Poco::Timespan& timeout);
103                /// Initializes the socket, sets the socket timeout and
104                /// establishes a connection to the TCP server at the given address.
105
106        void connectNB(const SocketAddress& address);
107                /// Initializes the socket and establishes a connection to
108                /// the TCP server at the given address. Prior to opening the
109                /// connection the socket is set to nonblocking mode.
110
111        void shutdownReceive();
112                /// Shuts down the receiving part of the socket connection.
113               
114        void shutdownSend();
115                /// Shuts down the sending part of the socket connection.
116               
117        void shutdown();
118                /// Shuts down both the receiving and the sending part
119                /// of the socket connection.
120       
121        int sendBytes(const void* buffer, int length, int flags = 0);
122                /// Sends the contents of the given buffer through
123                /// the socket.
124                ///
125                /// Returns the number of bytes sent, which may be
126                /// less than the number of bytes specified.
127                ///
128                /// Certain socket implementations may also return a negative
129                /// value denoting a certain condition.
130
131        int receiveBytes(void* buffer, int length, int flags = 0);
132                /// Receives data from the socket and stores it
133                /// in buffer. Up to length bytes are received.
134                ///
135                /// Returns the number of bytes received.
136                /// A return value of 0 means a graceful shutdown
137                /// of the connection from the peer.
138                ///
139                /// Throws a TimeoutException if a receive timeout has
140                /// been set and nothing is received within that interval.
141                /// Throws a NetException (or a subclass) in case of other errors.
142
143        void sendUrgent(unsigned char data);
144                /// Sends one byte of urgent data through
145                /// the socket.
146                ///
147                /// The data is sent with the MSG_OOB flag.
148                ///
149                /// The preferred way for a socket to receive urgent data
150                /// is by enabling the SO_OOBINLINE option.
151
152public:
153        StreamSocket(SocketImpl* pImpl);
154                /// Creates the Socket and attaches the given SocketImpl.
155                /// The socket takes owership of the SocketImpl.
156                ///
157                /// The SocketImpl must be a StreamSocketImpl, otherwise
158                /// an InvalidArgumentException will be thrown.
159
160        friend class ServerSocket;
161        friend class SocketIOS;
162};
163
164
165} } // namespace Poco::Net
166
167
168#endif // Net_StreamSocket_INCLUDED
Note: See TracBrowser for help on using the repository browser.