Skip to content

Commit 9cb9229

Browse files
committed
socket initialization and other fixes
1 parent 457e247 commit 9cb9229

17 files changed

Lines changed: 92 additions & 49 deletions

Net/include/Poco/Net/DatagramSocketImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DatagramSocketImpl.h
33
//
4-
// $Id: //poco/svn/Net/include/Poco/Net/DatagramSocketImpl.h#2 $
4+
// $Id: //poco/Main/Net/include/Poco/Net/DatagramSocketImpl.h#3 $
55
//
66
// Library: Net
77
// Package: Sockets
@@ -59,7 +59,7 @@ class Net_API DatagramSocketImpl: public SocketImpl
5959
/// be an IPv6 socket. Otherwise, it will be
6060
/// an IPv4 socket.
6161

62-
DatagramSocketImpl(IPAddress::Family family);
62+
explicit DatagramSocketImpl(IPAddress::Family family);
6363
/// Creates an unconnected datagram socket.
6464
///
6565
/// The socket will be created for the

Net/include/Poco/Net/HTTPServerSession.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HTTPServerSession.h
33
//
4-
// $Id: //poco/svn/Net/include/Poco/Net/HTTPServerSession.h#2 $
4+
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServerSession.h#5 $
55
//
66
// Library: Net
77
// Package: HTTPServer
@@ -43,23 +43,22 @@
4343
#include "Poco/Net/Net.h"
4444
#include "Poco/Net/HTTPSession.h"
4545
#include "Poco/Net/SocketAddress.h"
46+
#include "Poco/Net/HTTPServerSession.h"
47+
#include "Poco/Net/HTTPServerParams.h"
4648
#include "Poco/Timespan.h"
4749

4850

4951
namespace Poco {
5052
namespace Net {
5153

5254

53-
class HTTPServerParams;
54-
55-
5655
class Net_API HTTPServerSession: public HTTPSession
5756
/// This class handles the server side of a
5857
/// HTTP session. It is used internally by
5958
/// HTTPServer.
6059
{
6160
public:
62-
HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams);
61+
HTTPServerSession(const StreamSocket& socket, HTTPServerParams::Ptr pParams);
6362
/// Creates the HTTPServerSession.
6463

6564
virtual ~HTTPServerSession();

Net/include/Poco/Net/SocketAddress.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// SocketAddress.h
33
//
4-
// $Id: //poco/svn/Net/include/Poco/Net/SocketAddress.h#2 $
4+
// $Id: //poco/Main/Net/include/Poco/Net/SocketAddress.h#3 $
55
//
66
// Library: Net
77
// Package: NetCore
@@ -126,6 +126,9 @@ class Net_API SocketAddress
126126
std::string toString() const;
127127
/// Returns a string representation of the address.
128128

129+
IPAddress::Family family() const;
130+
/// Returns the address family of the host's address.
131+
129132
enum
130133
{
131134
MAX_ADDRESS_LENGTH =
@@ -156,6 +159,12 @@ inline void swap(SocketAddress& a1, SocketAddress& a2)
156159
}
157160

158161

162+
inline IPAddress::Family SocketAddress::family() const
163+
{
164+
return host().family();
165+
}
166+
167+
159168
} } // namespace Poco::Net
160169

161170

Net/include/Poco/Net/StreamSocket.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// StreamSocket.h
33
//
4-
// $Id: //poco/Main/Net/include/Poco/Net/StreamSocket.h#3 $
4+
// $Id: //poco/Main/Net/include/Poco/Net/StreamSocket.h#4 $
55
//
66
// Library: Net
77
// Package: Sockets
@@ -66,6 +66,15 @@ class Net_API StreamSocket: public Socket
6666
/// Creates a stream socket and connects it to
6767
/// the socket specified by address.
6868

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+
6978
StreamSocket(const Socket& socket);
7079
/// Creates the StreamSocket with the SocketImpl
7180
/// from another socket. The SocketImpl must be

Net/include/Poco/Net/StreamSocketImpl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// StreamSocketImpl.h
33
//
4-
// $Id: //poco/svn/Net/include/Poco/Net/StreamSocketImpl.h#2 $
4+
// $Id: //poco/Main/Net/include/Poco/Net/StreamSocketImpl.h#3 $
55
//
66
// Library: Net
77
// Package: Sockets
@@ -54,6 +54,10 @@ class Net_API StreamSocketImpl: public SocketImpl
5454
public:
5555
StreamSocketImpl();
5656
/// Creates a StreamSocketImpl.
57+
58+
explicit StreamSocketImpl(IPAddress::Family addressFamily);
59+
/// Creates a SocketImpl, with the underlying
60+
/// socket initialized for the given address family.
5761

5862
StreamSocketImpl(poco_socket_t sockfd);
5963
/// Creates a StreamSocketImpl using the given native socket.

Net/src/DatagramSocketImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DatagramSocketImpl.cpp
33
//
4-
// $Id: //poco/svn/Net/src/DatagramSocketImpl.cpp#2 $
4+
// $Id: //poco/Main/Net/src/DatagramSocketImpl.cpp#7 $
55
//
66
// Library: Net
77
// Package: Sockets
@@ -60,7 +60,6 @@ DatagramSocketImpl::DatagramSocketImpl(IPAddress::Family family)
6060
init(AF_INET6);
6161
#endif
6262
else throw InvalidArgumentException("Invalid or unsupported address family passed to DatagramSocketImpl");
63-
6463
}
6564

6665

Net/src/HTTPClientSession.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HTTPClientSession.cpp
33
//
4-
// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#21 $
4+
// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#22 $
55
//
66
// Library: Net
77
// Package: HTTPClient
@@ -175,7 +175,7 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
175175
_pResponseStream = 0;
176176

177177
bool keepAlive = getKeepAlive();
178-
if (connected() && !keepAlive || mustReconnect())
178+
if ((connected() && !keepAlive) || mustReconnect())
179179
{
180180
close();
181181
_mustReconnect = false;

Net/src/HTTPServerSession.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HTTPServerSession.cpp
33
//
4-
// $Id: //poco/Main/Net/src/HTTPServerSession.cpp#9 $
4+
// $Id: //poco/Main/Net/src/HTTPServerSession.cpp#11 $
55
//
66
// Library: Net
77
// Package: HTTPServer
@@ -35,14 +35,13 @@
3535

3636

3737
#include "Poco/Net/HTTPServerSession.h"
38-
#include "Poco/Net/HTTPServerParams.h"
3938

4039

4140
namespace Poco {
4241
namespace Net {
4342

4443

45-
HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams):
44+
HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams::Ptr pParams):
4645
HTTPSession(socket, pParams->getKeepAlive()),
4746
_firstRequest(true),
4847
_keepAliveTimeout(pParams->getKeepAliveTimeout()),

Net/src/HostEntry.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HostEntry.cpp
33
//
4-
// $Id: //poco/Main/Net/src/HostEntry.cpp#8 $
4+
// $Id: //poco/Main/Net/src/HostEntry.cpp#9 $
55
//
66
// Library: Net
77
// Package: NetCore
@@ -89,9 +89,21 @@ HostEntryImpl::HostEntryImpl(struct addrinfo* ainfo)
8989
for (struct addrinfo* ai = ainfo; ai; ai = ai->ai_next)
9090
{
9191
if (ai->ai_canonname)
92+
{
9293
_name.assign(ai->ai_canonname);
94+
}
9395
else if (ai->ai_addrlen && ai->ai_addr)
94-
_addresses.push_back(IPAddress(ai->ai_addr, (poco_socklen_t) ai->ai_addrlen));
96+
{
97+
switch (ai->ai_addr->sa_family)
98+
{
99+
case AF_INET:
100+
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in*>(&ai->ai_addr)->sin_addr, sizeof(in_addr)));
101+
break;
102+
case AF_INET6:
103+
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in6*>(&ai->ai_addr)->sin6_addr, sizeof(in6_addr)));
104+
break;
105+
}
106+
}
95107
}
96108
}
97109

Net/src/ICMPPacket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// ICMPPacket.cpp
33
//
4-
// $Id: //poco/svn/Net/src/ICMPPacket.cpp#2 $
4+
// $Id: //poco/Main/Net/src/ICMPPacket.cpp#5 $
55
//
66
// Library: Net
77
// Package: ICMP

0 commit comments

Comments
 (0)