mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 20:59:45 +01:00
fixed GH #2492: Net::Socket::address() crash on Android
This commit is contained in:
@@ -18,11 +18,26 @@
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <string.h> // FD_SET needs memset on some platforms, so we can't use <cstring>
|
||||
|
||||
|
||||
#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
|
||||
#ifndef POCO_HAVE_FD_POLL
|
||||
#define POCO_HAVE_FD_POLL 1
|
||||
#endif
|
||||
#elif defined(POCO_OS_FAMILY_BSD)
|
||||
#ifndef POCO_HAVE_FD_POLL
|
||||
#define POCO_HAVE_FD_POLL 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_FD_EPOLL)
|
||||
#include <sys/epoll.h>
|
||||
#elif defined(POCO_HAVE_FD_POLL)
|
||||
#ifndef _WIN32
|
||||
#include <poll.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(sun) || defined(__sun) || defined(__sun__)
|
||||
@@ -89,8 +104,8 @@ SocketImpl* SocketImpl::acceptConnection(SocketAddress& clientAddr)
|
||||
{
|
||||
if (_sockfd == POCO_INVALID_SOCKET) throw InvalidSocketException();
|
||||
|
||||
char buffer[SocketAddress::MAX_ADDRESS_LENGTH];
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(buffer);
|
||||
sockaddr_storage buffer;
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(&buffer);
|
||||
poco_socklen_t saLen = sizeof(buffer);
|
||||
poco_socket_t sd;
|
||||
do
|
||||
@@ -189,7 +204,7 @@ void SocketImpl::connectNB(const SocketAddress& address)
|
||||
|
||||
void SocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||||
{
|
||||
bind(address, reuseAddress, true);
|
||||
bind(address, reuseAddress, reuseAddress);
|
||||
}
|
||||
|
||||
|
||||
@@ -375,8 +390,8 @@ int SocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, in
|
||||
}
|
||||
}
|
||||
|
||||
char abuffer[SocketAddress::MAX_ADDRESS_LENGTH];
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(abuffer);
|
||||
sockaddr_storage abuffer;
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(&abuffer);
|
||||
poco_socklen_t saLen = sizeof(abuffer);
|
||||
int rc;
|
||||
do
|
||||
@@ -414,7 +429,7 @@ void SocketImpl::sendUrgent(unsigned char data)
|
||||
|
||||
int SocketImpl::available()
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
ioctl(FIONREAD, result);
|
||||
return result;
|
||||
}
|
||||
@@ -650,8 +665,8 @@ SocketAddress SocketImpl::address()
|
||||
{
|
||||
if (_sockfd == POCO_INVALID_SOCKET) throw InvalidSocketException();
|
||||
|
||||
char buffer[SocketAddress::MAX_ADDRESS_LENGTH];
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(buffer);
|
||||
sockaddr_storage buffer;
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(&buffer);
|
||||
poco_socklen_t saLen = sizeof(buffer);
|
||||
int rc = ::getsockname(_sockfd, pSA, &saLen);
|
||||
if (rc == 0)
|
||||
@@ -666,8 +681,8 @@ SocketAddress SocketImpl::peerAddress()
|
||||
{
|
||||
if (_sockfd == POCO_INVALID_SOCKET) throw InvalidSocketException();
|
||||
|
||||
char buffer[SocketAddress::MAX_ADDRESS_LENGTH];
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(buffer);
|
||||
sockaddr_storage buffer;
|
||||
struct sockaddr* pSA = reinterpret_cast<struct sockaddr*>(&buffer);
|
||||
poco_socklen_t saLen = sizeof(buffer);
|
||||
int rc = ::getpeername(_sockfd, pSA, &saLen);
|
||||
if (rc == 0)
|
||||
@@ -939,7 +954,7 @@ void SocketImpl::initSocket(int af, int type, int proto)
|
||||
// will crash the process. This only happens on UNIX, and not Linux.
|
||||
//
|
||||
// In order to have POCO sockets behave the same across platforms, it is
|
||||
// best to just ignore SIGPIPE all together.
|
||||
// best to just ignore SIGPIPE altogether.
|
||||
setOption(SOL_SOCKET, SO_NOSIGPIPE, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user