mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
socket initialization and other fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// DatagramSocketImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/DatagramSocketImpl.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/DatagramSocketImpl.cpp#7 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -60,7 +60,6 @@ DatagramSocketImpl::DatagramSocketImpl(IPAddress::Family family)
|
||||
init(AF_INET6);
|
||||
#endif
|
||||
else throw InvalidArgumentException("Invalid or unsupported address family passed to DatagramSocketImpl");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPClientSession.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#21 $
|
||||
// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#22 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPClient
|
||||
@@ -175,7 +175,7 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
|
||||
_pResponseStream = 0;
|
||||
|
||||
bool keepAlive = getKeepAlive();
|
||||
if (connected() && !keepAlive || mustReconnect())
|
||||
if ((connected() && !keepAlive) || mustReconnect())
|
||||
{
|
||||
close();
|
||||
_mustReconnect = false;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPServerSession.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/HTTPServerSession.cpp#9 $
|
||||
// $Id: //poco/Main/Net/src/HTTPServerSession.cpp#11 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPServer
|
||||
@@ -35,14 +35,13 @@
|
||||
|
||||
|
||||
#include "Poco/Net/HTTPServerSession.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams* pParams):
|
||||
HTTPServerSession::HTTPServerSession(const StreamSocket& socket, HTTPServerParams::Ptr pParams):
|
||||
HTTPSession(socket, pParams->getKeepAlive()),
|
||||
_firstRequest(true),
|
||||
_keepAliveTimeout(pParams->getKeepAliveTimeout()),
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HostEntry.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/HostEntry.cpp#8 $
|
||||
// $Id: //poco/Main/Net/src/HostEntry.cpp#9 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: NetCore
|
||||
@@ -89,9 +89,21 @@ HostEntryImpl::HostEntryImpl(struct addrinfo* ainfo)
|
||||
for (struct addrinfo* ai = ainfo; ai; ai = ai->ai_next)
|
||||
{
|
||||
if (ai->ai_canonname)
|
||||
{
|
||||
_name.assign(ai->ai_canonname);
|
||||
}
|
||||
else if (ai->ai_addrlen && ai->ai_addr)
|
||||
_addresses.push_back(IPAddress(ai->ai_addr, (poco_socklen_t) ai->ai_addrlen));
|
||||
{
|
||||
switch (ai->ai_addr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in*>(&ai->ai_addr)->sin_addr, sizeof(in_addr)));
|
||||
break;
|
||||
case AF_INET6:
|
||||
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in6*>(&ai->ai_addr)->sin6_addr, sizeof(in6_addr)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ICMPPacket.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/ICMPPacket.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/ICMPPacket.cpp#5 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: ICMP
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MultipartReader.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/MultipartReader.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/MultipartReader.cpp#13 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Messages
|
||||
@@ -76,7 +76,7 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
int ch = _istr.get();
|
||||
if (ch == eof) return -1;
|
||||
*buffer++ = (char) ch; ++n;
|
||||
if (ch == '\n' || ch == '\r' && _istr.peek() == '\n')
|
||||
if (ch == '\n' || (ch == '\r' && _istr.peek() == '\n'))
|
||||
{
|
||||
if (ch == '\r')
|
||||
{
|
||||
@@ -102,7 +102,7 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
}
|
||||
if (it == end)
|
||||
{
|
||||
if (ch == '\n' || ch == '\r' && _istr.peek() == '\n')
|
||||
if (ch == '\n' || (ch == '\r' && _istr.peek() == '\n'))
|
||||
{
|
||||
if (ch == '\r')
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// QuotedPrintableEncoder.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/QuotedPrintableEncoder.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/QuotedPrintableEncoder.cpp#7 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Messages
|
||||
@@ -83,7 +83,7 @@ int QuotedPrintableEncoderBuf::writeToDevice(char c)
|
||||
_pending = charToInt(c);
|
||||
return _pending;
|
||||
}
|
||||
else if (c == '\r' || c == '\n' || c > 32 && c < 127 && c != '=')
|
||||
else if (c == '\r' || c == '\n' || (c > 32 && c < 127 && c != '='))
|
||||
{
|
||||
writeRaw(c);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// RawSocketImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/RawSocketImpl.cpp#2 $
|
||||
// $Id: //poco/Main/Net/src/RawSocketImpl.cpp#10 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SocketImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/SocketImpl.cpp#26 $
|
||||
// $Id: //poco/Main/Net/src/SocketImpl.cpp#28 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -41,12 +41,12 @@
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <string.h> // FD_SET needs memset on some platforms, so we can't use <cstring>
|
||||
#if defined(POCO_HAVE_FD_POLL)
|
||||
#include <poll.h>
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#if defined(sun) || defined(__sun) || defined(__sun__)
|
||||
#include <unistd.h>
|
||||
#include <stropts.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using Poco::IOException;
|
||||
using Poco::TimeoutException;
|
||||
@@ -120,9 +120,10 @@ void SocketImpl::connect(const SocketAddress& address)
|
||||
|
||||
void SocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
|
||||
{
|
||||
poco_assert (_sockfd == POCO_INVALID_SOCKET);
|
||||
|
||||
init(address.af());
|
||||
if (_sockfd == POCO_INVALID_SOCKET)
|
||||
{
|
||||
init(address.af());
|
||||
}
|
||||
setBlocking(false);
|
||||
try
|
||||
{
|
||||
@@ -330,7 +331,7 @@ int SocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, in
|
||||
void SocketImpl::sendUrgent(unsigned char data)
|
||||
{
|
||||
poco_assert (_sockfd != POCO_INVALID_SOCKET);
|
||||
|
||||
|
||||
int rc = ::send(_sockfd, reinterpret_cast<const char*>(&data), sizeof(data), MSG_OOB);
|
||||
if (rc < 0) error();
|
||||
}
|
||||
@@ -346,24 +347,21 @@ int SocketImpl::available()
|
||||
|
||||
bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
{
|
||||
poco_assert (_sockfd != POCO_INVALID_SOCKET);
|
||||
|
||||
#if defined(POCO_HAVE_FD_POLL)
|
||||
|
||||
pollfd pollBuf;
|
||||
|
||||
|
||||
memset(&pollBuf, 0, sizeof(pollfd));
|
||||
pollBuf.fd = _sockfd;
|
||||
if (mode & SELECT_READ) pollBuf.events |= POLLIN;
|
||||
if (mode & SELECT_WRITE) pollBuf.events |= POLLOUT;
|
||||
|
||||
|
||||
Poco::Timespan remainingTime(timeout);
|
||||
int rc;
|
||||
do
|
||||
{
|
||||
Poco::Timestamp start;
|
||||
rc = ::poll(&pollBuf, 1, remainingTime.totalMilliseconds());
|
||||
|
||||
|
||||
if (rc < 0 && lastError() == POCO_EINTR)
|
||||
{
|
||||
Poco::Timestamp end;
|
||||
@@ -373,10 +371,9 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
else
|
||||
remainingTime = 0;
|
||||
}
|
||||
} while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
}
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
#else
|
||||
|
||||
fd_set fdRead;
|
||||
fd_set fdWrite;
|
||||
fd_set fdExcept;
|
||||
@@ -415,9 +412,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
}
|
||||
}
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // POCO_HAVE_FD_POLL
|
||||
if (rc < 0) error();
|
||||
return rc > 0;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// StreamSocket.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/StreamSocket.cpp#9 $
|
||||
// $Id: //poco/Main/Net/src/StreamSocket.cpp#10 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -57,6 +57,11 @@ StreamSocket::StreamSocket(const SocketAddress& address): Socket(new StreamSocke
|
||||
}
|
||||
|
||||
|
||||
StreamSocket::StreamSocket(IPAddress::Family family): Socket(new StreamSocketImpl(family))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StreamSocket::StreamSocket(const Socket& socket): Socket(socket)
|
||||
{
|
||||
if (!dynamic_cast<StreamSocketImpl*>(impl()))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// StreamSocketImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/StreamSocketImpl.cpp#8 $
|
||||
// $Id: //poco/Main/Net/src/StreamSocketImpl.cpp#9 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -46,6 +46,18 @@ StreamSocketImpl::StreamSocketImpl()
|
||||
}
|
||||
|
||||
|
||||
StreamSocketImpl::StreamSocketImpl(IPAddress::Family family)
|
||||
{
|
||||
if (family == IPAddress::IPv4)
|
||||
init(AF_INET);
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
else if (family == IPAddress::IPv6)
|
||||
init(AF_INET6);
|
||||
#endif
|
||||
else throw InvalidArgumentException("Invalid or unsupported address family passed to StreamSocketImpl");
|
||||
}
|
||||
|
||||
|
||||
StreamSocketImpl::StreamSocketImpl(poco_socket_t sockfd): SocketImpl(sockfd)
|
||||
{
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// TCPServerDispatcher.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/src/TCPServerDispatcher.cpp#10 $
|
||||
// $Id: //poco/Main/Net/src/TCPServerDispatcher.cpp#11 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: TCPServer
|
||||
@@ -139,7 +139,7 @@ void TCPServerDispatcher::run()
|
||||
}
|
||||
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (_stopped || _currentThreads > 1 && _queue.empty())
|
||||
if (_stopped || (_currentThreads > 1 && _queue.empty()))
|
||||
{
|
||||
--_currentThreads;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user