This commit is contained in:
manojampalam 2016-02-28 15:55:55 -08:00
parent 6c4b701dd6
commit ef3f1691e8
4 changed files with 15 additions and 11 deletions

View File

@ -74,6 +74,9 @@ int socket_prepare(char* ip)
return 0;
}
#define READ_BUf_SIZE 1024 * 1024 * 2
#define WRITE_BUF_SIZE 1024 * 1024 * 5
namespace UnitTests
{
TEST_CLASS(SocketIOTests)
@ -99,7 +102,7 @@ namespace UnitTests
w32posix_done();
}
TEST_METHOD(TestMethod1)
TEST_METHOD(socketio)
{
int ret;
ret = socket_prepare("::1");
@ -117,10 +120,9 @@ namespace UnitTests
set_nonblock(c);
set_nonblock(s);
#define WRITE_BUF_SIZE 1024 * 1024 * 5
char to_write[1024 * 1024 * 5]; //5MB
#define READ_BUf_SIZE 1024 * 1024 * 2
char read_to[READ_BUf_SIZE]; //2MB
char *to_write = (char*)malloc(WRITE_BUF_SIZE); //5MB
char *read_to = (char*)malloc(READ_BUf_SIZE); //2MB
//write from c, read from s
fd_set read_set;
@ -177,7 +179,7 @@ namespace UnitTests
}
//Assert::AreEqual(bytes_written, bytes_read, L"", LINE_INFO());
Assert::AreEqual((bytes_written == bytes_read)? 1:0, TRUE, L"", LINE_INFO());
}
TEST_METHOD(TestMethod)

View File

@ -716,8 +716,7 @@ int socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namele
//close event handle
CloseHandle(pio->write_overlapped.hEvent);
pio->write_overlapped.hEvent = 0;
if (pio->write_details.error) {
errno = errno_from_WSAError(pio->write_details.error);
debug("ERROR: async io completed with error: %d, io:%p", errno, pio);
@ -726,12 +725,14 @@ int socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namele
if (0 != setsockopt(pio->sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, NULL, 0))
{
int i = WSAGetLastError();
errno = errno_from_WSALastError();
debug("ERROR: setsockopt failed:%d, io:%p", errno, pio);
return NULL;
return -1;
}
//Reset any state used during connect
ZeroMemory(&pio->write_details, sizeof(pio->write_details));
pio->type = SOCK_FD;
return 0;
}

View File

@ -84,7 +84,7 @@ BOOL w32_io_is_blocking(struct w32_io* pio)
}
BOOL w32_io_is_io_available(struct w32_io* pio, BOOL rd) {
if ((pio->type == LISTEN_FD) || (pio->type == SOCK_FD)) {
if (pio->type <= SOCK_FD) {
return socketio_is_io_available(pio, rd);
}
else {

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include "debug.h"
//order to be maintained
enum w32_io_type {
UNKOWN_FD = 0,
LISTEN_FD,