Made SocketCore::readData() and readDataFrom() take void*

pull/43/head
Tatsuhiro Tsujikawa 2013-01-11 17:03:59 +09:00
parent 8ba0d58ee1
commit 357e4b1a77
2 changed files with 9 additions and 18 deletions

View File

@ -825,14 +825,15 @@ ssize_t SocketCore::writeData(const void* data, size_t len)
return ret; return ret;
} }
void SocketCore::readData(char* data, size_t& len) void SocketCore::readData(void* data, size_t& len)
{ {
ssize_t ret = 0; ssize_t ret = 0;
wantRead_ = false; wantRead_ = false;
wantWrite_ = false; wantWrite_ = false;
if(!secure_) { if(!secure_) {
while((ret = recv(sockfd_, data, len, 0)) == -1 && // Cast for Windows recv()
while((ret = recv(sockfd_, reinterpret_cast<char*>(data), len, 0)) == -1 &&
SOCKET_ERRNO == A2_EINTR); SOCKET_ERRNO == A2_EINTR);
int errNum = SOCKET_ERRNO; int errNum = SOCKET_ERRNO;
if(ret == -1) { if(ret == -1) {
@ -1247,7 +1248,7 @@ ssize_t SocketCore::writeData(const void* data, size_t len,
return r; return r;
} }
ssize_t SocketCore::readDataFrom(char* data, size_t len, ssize_t SocketCore::readDataFrom(void* data, size_t len,
std::pair<std::string /* numerichost */, std::pair<std::string /* numerichost */,
uint16_t /* port */>& sender) uint16_t /* port */>& sender)
{ {
@ -1256,7 +1257,9 @@ ssize_t SocketCore::readDataFrom(char* data, size_t len,
sockaddr_union sockaddr; sockaddr_union sockaddr;
socklen_t sockaddrlen = sizeof(sockaddr); socklen_t sockaddrlen = sizeof(sockaddr);
ssize_t r; ssize_t r;
while((r = recvfrom(sockfd_, data, len, 0, &sockaddr.sa, &sockaddrlen)) == -1 // Cast for Windows recvfrom()
while((r = recvfrom(sockfd_, reinterpret_cast<char*>(data), len, 0,
&sockaddr.sa, &sockaddrlen)) == -1
&& A2_EINTR == SOCKET_ERRNO); && A2_EINTR == SOCKET_ERRNO);
int errNum = SOCKET_ERRNO; int errNum = SOCKET_ERRNO;
if(r == -1) { if(r == -1) {

View File

@ -279,24 +279,12 @@ public:
* @param len the maximum size data can store. This method assigns * @param len the maximum size data can store. This method assigns
* the number of bytes read to len. * the number of bytes read to len.
*/ */
void readData(char* data, size_t& len); void readData(void* data, size_t& len);
void readData(unsigned char* data, size_t& len) ssize_t readDataFrom(void* data, size_t len,
{
readData(reinterpret_cast<char*>(data), len);
}
ssize_t readDataFrom(char* data, size_t len,
std::pair<std::string /* numerichost */, std::pair<std::string /* numerichost */,
uint16_t /* port */>& sender); uint16_t /* port */>& sender);
ssize_t readDataFrom(unsigned char* data, size_t len,
std::pair<std::string /* numerichost */,
uint16_t /* port */>& sender)
{
return readDataFrom(reinterpret_cast<char*>(data), len, sender);
}
#ifdef ENABLE_SSL #ifdef ENABLE_SSL
// Performs TLS server side handshake. If handshake is completed, // Performs TLS server side handshake. If handshake is completed,
// returns true. If handshake has not been done yet, returns false. // returns true. If handshake has not been done yet, returns false.