mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 14:04:59 +02:00
updating debug log info
This commit is contained in:
parent
173b000a76
commit
fde5fdad4d
@ -40,7 +40,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
|
||||
/* some other error*/
|
||||
else {
|
||||
errno = EOTHER;
|
||||
debug("ERROR: unxpected wait end with error: %d", ret);
|
||||
debug("ERROR: unxpected wait end: %d", ret);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ int
|
||||
socketio_acceptEx(struct w32_io* pio) {
|
||||
struct acceptEx_context *context;
|
||||
|
||||
debug2("io:%p", pio);
|
||||
debug3("acceptEx - io:%p", pio);
|
||||
if (pio->internal.context == NULL) {
|
||||
GUID GuidAcceptEx = WSAID_ACCEPTEX;
|
||||
GUID GuidGetAcceptExSockaddrs = WSAID_GETACCEPTEXSOCKADDRS;
|
||||
@ -71,7 +71,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
(struct acceptEx_context*)malloc(sizeof(struct acceptEx_context));
|
||||
if (context == NULL) {
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
memset(context, 0, sizeof(struct acceptEx_context));
|
||||
@ -83,7 +83,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
{
|
||||
free(context);
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - Ioctl1 ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
{
|
||||
free(context);
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - Ioctl2 ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
pio->read_overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if ((pio->read_overlapped.hEvent) == NULL) {
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - CreateEvent() ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -122,7 +122,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
context->accept_socket = socket(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (context->accept_socket == INVALID_SOCKET) {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - socket() ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ socketio_acceptEx(struct w32_io* pio) {
|
||||
/* if overlapped io is in progress, we are good */
|
||||
if (WSAGetLastError() != ERROR_IO_PENDING) {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("acceptEx - AcceptEx() ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,7 @@ CALLBACK WSARecvCompletionRoutine(
|
||||
{
|
||||
struct w32_io* pio =
|
||||
(struct w32_io*)((char*)lpOverlapped - offsetof(struct w32_io, read_overlapped));
|
||||
debug2("io:%p, pending_state:%d, flags:%d, error:%d, received:%d",
|
||||
debug2("WSARecvCompletionCB - io:%p, pending_state:%d, flags:%d, error:%d, received:%d",
|
||||
pio, pio->read_details.pending, dwFlags, dwError, cbTransferred);
|
||||
if (!dwError && !cbTransferred)
|
||||
dwError = ERROR_GRACEFUL_DISCONNECT;
|
||||
@ -178,7 +178,7 @@ socketio_WSARecv(struct w32_io* pio, BOOL* completed) {
|
||||
WSABUF wsabuf;
|
||||
DWORD recv_flags = 0;
|
||||
|
||||
debug2("pio: %p", pio);
|
||||
debug3("WSARecv - pio: %p", pio);
|
||||
if (completed)
|
||||
*completed = FALSE;
|
||||
|
||||
@ -191,7 +191,7 @@ socketio_WSARecv(struct w32_io* pio, BOOL* completed) {
|
||||
if (!wsabuf.buf)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("WSARecv - ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ socketio_WSARecv(struct w32_io* pio, BOOL* completed) {
|
||||
{
|
||||
pio->read_details.pending = TRUE;
|
||||
/* receive has completed but APC is pending to be scheduled */
|
||||
debug2("WSARecv returned 0, io:%p", pio);
|
||||
debug2("WSARecv - WSARecv() returned 0, io:%p", pio);
|
||||
if (completed)
|
||||
*completed = TRUE;
|
||||
}
|
||||
@ -216,12 +216,12 @@ socketio_WSARecv(struct w32_io* pio, BOOL* completed) {
|
||||
if (WSAGetLastError() == WSA_IO_PENDING)
|
||||
{
|
||||
/* io is initiated and pending */
|
||||
debug2("WSARecv reported IO pending");
|
||||
debug2("WSARecv - reported IO pending");
|
||||
pio->read_details.pending = TRUE;
|
||||
}
|
||||
else {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR: io:%p %d", pio, errno);
|
||||
debug("WSARecv - WSARecv() ERROR: io:%p %d", pio, errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -235,7 +235,7 @@ socketio_socket(int domain, int type, int protocol) {
|
||||
struct w32_io *pio = (struct w32_io*)malloc(sizeof(struct w32_io));
|
||||
if (!pio) {
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("socket - ERROR:%d, io:%p", errno, pio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ socketio_socket(int domain, int type, int protocol) {
|
||||
if (pio->sock == INVALID_SOCKET) {
|
||||
errno = errno_from_WSALastError();
|
||||
free(pio);
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("socket - socket() ERROR:%d, io:%p", errno, pio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -256,7 +256,7 @@ socketio_socket(int domain, int type, int protocol) {
|
||||
int ret = (expr); \
|
||||
if (ret == SOCKET_ERROR) { \
|
||||
errno = errno_from_WSALastError(); \
|
||||
debug("ERROR:%d", errno); \
|
||||
debug("%s - ERROR:%d", __FUNCTION__, errno); \
|
||||
} \
|
||||
return ret; \
|
||||
} while (0)
|
||||
@ -269,7 +269,7 @@ socketio_setsockopt(struct w32_io* pio, int level, int optname, const char* optv
|
||||
(optname == TCP_NODELAY) || (optname == IPV6_V6ONLY))
|
||||
SET_ERRNO_ON_ERROR(setsockopt(pio->sock, level, optname, optval, optlen));
|
||||
else {
|
||||
debug("ERROR: unsupported optname:%d io:%p", optname, pio);
|
||||
debug("setsockop - ERROR: unsupported optname:%d io:%p", optname, pio);
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
@ -298,7 +298,7 @@ int
|
||||
socketio_listen(struct w32_io* pio, int backlog) {
|
||||
if (SOCKET_ERROR == listen(pio->sock, backlog)) {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d io:%p", errno, pio);
|
||||
debug("listen - listen() ERROR:%d io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
pio->internal.state = SOCK_LISTENING;
|
||||
@ -316,17 +316,17 @@ int
|
||||
socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
BOOL completed = FALSE;
|
||||
|
||||
debug2("io:%p", pio);
|
||||
debug3("recv - io:%p", pio);
|
||||
|
||||
if ((buf == NULL) || (len == 0)) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR, buf:%p, len:%d, io:%p", buf, len, pio);
|
||||
debug("recv - ERROR: invalid arguments, buf:%p, len:%d, io:%p", buf, len, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags != 0) {
|
||||
errno = ENOTSUP;
|
||||
debug("ERROR: flags are not currently supported, io:%p", pio);
|
||||
debug("recv - ERROR: flags are not currently supported, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
if (pio->read_details.pending) {
|
||||
/* if recv is now in blocking mode, wait for data to be available */
|
||||
if (w32_io_is_blocking(pio)) {
|
||||
debug2("io is pending, call is blocking, io:%p", pio);
|
||||
debug2("recv - io is pending, call is blocking, io:%p", pio);
|
||||
while (socketio_is_io_available(pio, TRUE) == FALSE) {
|
||||
if (0 != wait_for_any_event(NULL, 0, INFINITE))
|
||||
return -1;
|
||||
@ -342,7 +342,7 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
}
|
||||
else {
|
||||
errno = EAGAIN;
|
||||
debug2("Read is already pending, io:%p", pio);
|
||||
debug2("recv - io is already pending, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -355,7 +355,7 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
num_bytes_copied);
|
||||
pio->read_details.remaining -= num_bytes_copied;
|
||||
pio->read_details.completed += num_bytes_copied;
|
||||
debug2("returning %d bytes from prior completed IO, remaining:%d, io:%p",
|
||||
debug2("recv - returning %d bytes from prior completed IO, remaining:%d, io:%p",
|
||||
num_bytes_copied, pio->read_details.remaining, pio);
|
||||
return num_bytes_copied;
|
||||
}
|
||||
@ -364,14 +364,14 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
/* if there was an error on async call, return */
|
||||
if (pio->read_details.error) {
|
||||
if (pio->read_details.error == ERROR_GRACEFUL_DISCONNECT) {
|
||||
debug2("connection closed, io:%p", pio);
|
||||
debug2("recv - connection closed, io:%p", pio);
|
||||
/* connection is closed */
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
errno = errno_from_WSAError(pio->read_details.error);
|
||||
pio->read_details.error = 0;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("recv - from CB ERROR:%d, io:%p", pio->read_details.error, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -381,13 +381,13 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
|
||||
if (completed) {
|
||||
/* Let APC be scheduled */
|
||||
debug2("Letting APC to execute");
|
||||
debug2("recv - Letting APC to execute, io:%p", pio);
|
||||
if (wait_for_any_event(NULL, 0, 0) == -1)
|
||||
return -1;
|
||||
if (pio->read_details.pending) {
|
||||
/* this shouldn't be happening */
|
||||
errno = EOTHER;
|
||||
debug("ERROR: Unexpected IO state, io:%p", pio);
|
||||
debug("recv - ERROR: Unexpected IO state, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -395,7 +395,7 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
if (w32_io_is_blocking(pio))
|
||||
{
|
||||
/* wait until io is done */
|
||||
debug3("socket in blocking mode");
|
||||
debug3("recv - socket in blocking mode, io:%p", pio);
|
||||
while (socketio_is_io_available(pio, TRUE) == FALSE) {
|
||||
if (0 != wait_for_any_event(NULL, 0, INFINITE))
|
||||
return -1;
|
||||
@ -404,7 +404,7 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
else {
|
||||
if (socketio_is_io_available(pio, TRUE) == FALSE) {
|
||||
errno = EAGAIN;
|
||||
debug2("IO is pending, io:%p", pio);
|
||||
debug2("recv - IO is pending, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -417,13 +417,13 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
{
|
||||
if (pio->read_details.error == ERROR_GRACEFUL_DISCONNECT) {
|
||||
/* connection is closed */
|
||||
debug2("connection closed, io:%p", pio);
|
||||
debug2("recv - connection closed(2), io:%p", pio);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
errno = errno_from_WSAError(pio->read_details.error);
|
||||
pio->read_details.error = 0;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("recv - from CB(2) ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -433,14 +433,14 @@ socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
|
||||
memcpy(buf, pio->read_details.buf, num_bytes_copied);
|
||||
pio->read_details.remaining -= num_bytes_copied;
|
||||
pio->read_details.completed = num_bytes_copied;
|
||||
debug2("returning %d bytes from completed IO, remaining:%d, io:%p",
|
||||
debug2("recv - (2) returning %d bytes from completed IO, remaining:%d, io:%p",
|
||||
num_bytes_copied, pio->read_details.remaining, pio);
|
||||
return num_bytes_copied;
|
||||
}
|
||||
else {
|
||||
/* this should not happen */
|
||||
errno = EOTHER;
|
||||
debug("ERROR:Unexpected IO stated, io:%p", pio);
|
||||
debug("recv - (2) ERROR:Unexpected IO stated, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -456,13 +456,16 @@ CALLBACK WSASendCompletionRoutine(
|
||||
{
|
||||
struct w32_io* pio =
|
||||
(struct w32_io*)((char*)lpOverlapped - offsetof(struct w32_io, write_overlapped));
|
||||
debug2("io:%p, pending_state:%d, error:%d, sent:%d of remaining:%d",
|
||||
debug2("WSASendCB - io:%p, pending_state:%d, error:%d, sent:%d of remaining:%d",
|
||||
pio, pio->write_details.pending, dwError, cbTransferred,
|
||||
pio->write_details.remaining);
|
||||
pio->write_details.error = dwError;
|
||||
/* TODO - assert that remaining == cbTransferred */
|
||||
if ((dwError == 0) && (pio->write_details.remaining != cbTransferred))
|
||||
if ((dwError == 0) && (pio->write_details.remaining != cbTransferred)) {
|
||||
debug("WSASendCB - ERROR: broken assumption, io:%p, sent:%d, remaining:%d", pio,
|
||||
cbTransferred, pio->write_details.remaining);
|
||||
abort();
|
||||
}
|
||||
pio->write_details.remaining -= cbTransferred;
|
||||
pio->write_details.pending = FALSE;
|
||||
}
|
||||
@ -473,17 +476,17 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
int ret = 0;
|
||||
WSABUF wsabuf;
|
||||
|
||||
debug2("io:%p", pio);
|
||||
debug2("send - io:%p", pio);
|
||||
|
||||
if ((buf == NULL) || (len == 0)) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR, buf:%p, len:%d, io:%p", buf, len, pio);
|
||||
debug("send - ERROR invalid arguments, buf:%p, len:%d, io:%p", buf, len, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags != 0) {
|
||||
errno = ENOTSUP;
|
||||
debug("ERROR: flags are not currently supported, io:%p", pio);
|
||||
debug("send - ERROR: flags are not currently supported, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -492,7 +495,7 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
{
|
||||
if (w32_io_is_blocking(pio))
|
||||
{
|
||||
debug2("io is pending, call is blocking, io:%p", pio);
|
||||
debug2("send - io is pending, call is blocking, io:%p", pio);
|
||||
while (pio->write_details.pending) {
|
||||
if (wait_for_any_event(NULL, 0, INFINITE) == -1)
|
||||
return -1;
|
||||
@ -500,7 +503,7 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
}
|
||||
else {
|
||||
errno = EAGAIN;
|
||||
debug2("IO currently pending, EAGAIN, io:%p", pio);
|
||||
debug2("send - IO currently pending, EAGAIN, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -520,7 +523,7 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
if (!wsabuf.buf)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("send - ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -541,14 +544,14 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
if (ret == 0)
|
||||
{
|
||||
/* send has completed and APC is scheduled, let it run */
|
||||
debug2("WSASend returned 0, APC scheduled io:%p", pio);
|
||||
debug2("send - WSASend() returned 0, APC scheduled io:%p", pio);
|
||||
pio->write_details.pending = TRUE;
|
||||
pio->write_details.remaining = wsabuf.len;
|
||||
if (wait_for_any_event(NULL, 0, 0) == -1)
|
||||
return -1;
|
||||
if ((pio->write_details.pending) || (pio->write_details.remaining != 0)) {
|
||||
errno = EOTHER;
|
||||
debug("ERROR: Unexpected IO state, io:%p", pio);
|
||||
debug("send - ERROR: Unexpected IO state, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -559,24 +562,24 @@ socketio_send(struct w32_io* pio, const void *buf, size_t len, int flags) {
|
||||
if (WSAGetLastError() == WSA_IO_PENDING)
|
||||
{
|
||||
/* io is initiated and pending */
|
||||
debug2("WSASend reported IO pending, io:%p", pio);
|
||||
debug2("send - WSASend reported IO pending, io:%p", pio);
|
||||
pio->write_details.pending = TRUE;
|
||||
pio->write_details.remaining = wsabuf.len;
|
||||
if (w32_io_is_blocking(pio))
|
||||
{
|
||||
/* wait until io is done */
|
||||
debug3("waiting as socket is in blocking mode, io:%p", pio);
|
||||
debug3("send - waiting as socket is in blocking mode, io:%p", pio);
|
||||
while (pio->write_details.pending)
|
||||
if (wait_for_any_event(NULL, 0,INFINITE) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug3("returning %d", wsabuf.len);
|
||||
debug3("send - returning %d, io:%p", wsabuf.len, pio);
|
||||
return wsabuf.len;
|
||||
}
|
||||
else {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("send - WSASend() ERROR:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -591,12 +594,14 @@ socketio_shutdown(struct w32_io* pio, int how) {
|
||||
/* socket close() implementation */
|
||||
int
|
||||
socketio_close(struct w32_io* pio) {
|
||||
debug2("io:%p", pio);
|
||||
debug2("close - io:%p", pio);
|
||||
closesocket(pio->sock);
|
||||
/* wait for pending io to abort */
|
||||
SleepEx(0, TRUE);
|
||||
if (pio->read_details.pending || pio->write_details.pending)
|
||||
debug2("IO is still pending on closed socket. read:%d, write:%d, io:%p", pio->read_details.pending, pio->write_details.pending, pio);
|
||||
if (pio->read_details.pending || pio->write_details.pending) {
|
||||
debug2("close - IO is still pending on closed socket. read:%d, write:%d, io:%p", pio->read_details.pending, pio->write_details.pending, pio);
|
||||
DebugBreak();
|
||||
}
|
||||
if (pio->internal.state == SOCK_LISTENING) {
|
||||
if (pio->read_overlapped.hEvent)
|
||||
CloseHandle(pio->read_overlapped.hEvent);
|
||||
@ -634,7 +639,7 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen) {
|
||||
struct sockaddr *local_address,*remote_address;
|
||||
int local_address_len, remote_address_len;
|
||||
|
||||
debug2("io:%p", pio);
|
||||
debug3("accept - io:%p", pio);
|
||||
/* start io if not already started */
|
||||
if (pio->read_details.pending == FALSE) {
|
||||
if (socketio_acceptEx(pio) != 0) {
|
||||
@ -646,7 +651,7 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen) {
|
||||
/* block until accept io is complete */
|
||||
while (FALSE == socketio_is_io_available(pio, TRUE))
|
||||
{
|
||||
if (0 != wait_for_any_event(&pio->read_overlapped.hEvent,
|
||||
if (-1 == wait_for_any_event(&pio->read_overlapped.hEvent,
|
||||
1, INFINITE))
|
||||
{
|
||||
return NULL;
|
||||
@ -669,21 +674,21 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen) {
|
||||
|
||||
if (pio->read_details.error) {
|
||||
errno = errno_from_WSAError(pio->read_details.error);
|
||||
debug("ERROR: async io completed with error: %d, io:%p", errno, pio);
|
||||
debug("accept - ERROR: async io completed with error: %d, io:%p", errno, pio);
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if (0 != setsockopt(context->accept_socket, SOL_SOCKET,
|
||||
SO_UPDATE_ACCEPT_CONTEXT, (char*)&pio->sock, sizeof(pio->sock))) {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR: setsockopt failed:%d, io:%p", errno, pio);
|
||||
debug("accept - ERROR: setsockopt failed:%d, io:%p", errno, pio);
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
accept_io = (struct w32_io*)malloc(sizeof(struct w32_io));
|
||||
if (!accept_io) {
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("accept - ERROR:%d, io:%p", errno, pio);
|
||||
goto on_error;
|
||||
}
|
||||
memset(accept_io, 0, sizeof(struct w32_io));
|
||||
@ -726,7 +731,7 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
|
||||
GUID connectex_guid = WSAID_CONNECTEX;
|
||||
LPFN_CONNECTEX ConnectEx;
|
||||
|
||||
debug("io:%p", pio);
|
||||
debug3("connectex - io:%p", pio);
|
||||
if (name->sa_family == AF_INET6) {
|
||||
ZeroMemory(&tmp_addr6, sizeof(tmp_addr6));
|
||||
tmp_addr6.sin6_family = AF_INET6;
|
||||
@ -743,14 +748,14 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
|
||||
}
|
||||
else {
|
||||
errno = ENOTSUP;
|
||||
debug("ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio);
|
||||
debug("connectex - ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SOCKET_ERROR == bind(pio->sock, tmp_addr, (int)tmp_addr_len))
|
||||
{
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR: bind failed :%d, io:%p", errno, pio);
|
||||
debug("connectex - ERROR: bind failed :%d, io:%p", WSAGetLastError(), pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -760,14 +765,14 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
|
||||
&tmp_bytes, NULL, NULL))
|
||||
{
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("connectex - ioctl ERROR:%d, io:%p", WSAGetLastError(), pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((!pio->write_overlapped.hEvent)
|
||||
&& ((pio->write_overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL)) {
|
||||
errno = ENOMEM;
|
||||
debug("ERROR:%d, io:%p", errno, pio);
|
||||
debug("connectex - ERROR CreateEvent failed:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -782,7 +787,7 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
|
||||
CloseHandle(pio->write_overlapped.hEvent);
|
||||
pio->write_overlapped.hEvent = 0;
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR ConnectEx :%d, io:%p", errno, pio);
|
||||
debug("connectex - ERROR ConnectEx() :%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -796,6 +801,7 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
|
||||
int
|
||||
socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namelen) {
|
||||
|
||||
debug3("connect - io:%p", pio);
|
||||
if (pio->write_details.pending == FALSE) {
|
||||
if (-1 == socketio_connectex(pio, name, namelen))
|
||||
return -1;
|
||||
@ -804,7 +810,7 @@ socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namelen) {
|
||||
if (w32_io_is_blocking(pio)) {
|
||||
/* block until connect io is complete */
|
||||
while (FALSE == socketio_is_io_available(pio, TRUE)) {
|
||||
if (0 != wait_for_any_event(&pio->write_overlapped.hEvent,
|
||||
if (-1 == wait_for_any_event(&pio->write_overlapped.hEvent,
|
||||
1, INFINITE))
|
||||
return -1;
|
||||
}
|
||||
@ -813,7 +819,7 @@ socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namelen) {
|
||||
/* if i/o is not ready */
|
||||
if (FALSE == socketio_is_io_available(pio, TRUE)) {
|
||||
errno = EINPROGRESS;
|
||||
debug2("connect is in progress, io:%p", pio);
|
||||
debug2("connect - in progress, io:%p", pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -821,13 +827,13 @@ socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namelen) {
|
||||
|
||||
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);
|
||||
debug("connect - ERROR: async io completed with error: %d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != setsockopt(pio->sock, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0)) {
|
||||
errno = errno_from_WSALastError();
|
||||
debug("ERROR: setsockopt failed:%d, io:%p", errno, pio);
|
||||
debug("connect - ERROR: setsockopt failed:%d, io:%p", errno, pio);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -884,7 +890,7 @@ socketio_on_select(struct w32_io* pio, BOOL rd) {
|
||||
|
||||
enum w32_io_sock_state sock_state = pio->internal.state;
|
||||
|
||||
debug2("io:%p type:%d rd:%d", pio, pio->type, rd);
|
||||
debug2("on_select - io:%p type:%d rd:%d", pio, pio->type, rd);
|
||||
|
||||
//nothing to do for writes (that includes connect)
|
||||
if (!rd)
|
||||
|
@ -130,10 +130,11 @@ w32_io_on_select(struct w32_io* pio, BOOL rd)
|
||||
}
|
||||
|
||||
#define CHECK_FD(fd) do { \
|
||||
debug3("%s fd:%d", __FUNCTION__, fd); \
|
||||
errno = 0; \
|
||||
if ((fd < 0) || (fd > MAX_FDS - 1) || fd_table.w32_ios[fd] == NULL) { \
|
||||
errno = EBADF; \
|
||||
debug("ERROR: bad fd: %d", fd); \
|
||||
debug("%s ERROR: bad fd: %d", __FUNCTION__, fd); \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0)
|
||||
@ -142,7 +143,7 @@ w32_io_on_select(struct w32_io* pio, BOOL rd)
|
||||
errno = 0; \
|
||||
if (pio->type != SOCK_FD) { \
|
||||
errno = ENOTSOCK; \
|
||||
debug("ERROR: non sock fd type:%d", pio->type); \
|
||||
debug("%s ERROR: not sock :%d", __FUNCTION__, pio->type); \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0)
|
||||
@ -169,7 +170,7 @@ w32_socket(int domain, int type, int protocol) {
|
||||
int
|
||||
w32_accept(int fd, struct sockaddr* addr, int* addrlen)
|
||||
{
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
int min_index = fd_table_get_min_index();
|
||||
@ -190,7 +191,7 @@ w32_accept(int fd, struct sockaddr* addr, int* addrlen)
|
||||
|
||||
int
|
||||
w32_setsockopt(int fd, int level, int optname, const char* optval, int optlen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_setsockopt(fd_table.w32_ios[fd], level, optname, optval, optlen);
|
||||
@ -198,7 +199,7 @@ w32_setsockopt(int fd, int level, int optname, const char* optval, int optlen) {
|
||||
|
||||
int
|
||||
w32_getsockopt(int fd, int level, int optname, char* optval, int* optlen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_getsockopt(fd_table.w32_ios[fd], level, optname, optval, optlen);
|
||||
@ -206,7 +207,7 @@ w32_getsockopt(int fd, int level, int optname, char* optval, int* optlen) {
|
||||
|
||||
int
|
||||
w32_getsockname(int fd, struct sockaddr* name, int* namelen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_getsockname(fd_table.w32_ios[fd], name, namelen);
|
||||
@ -214,7 +215,7 @@ w32_getsockname(int fd, struct sockaddr* name, int* namelen) {
|
||||
|
||||
int
|
||||
w32_getpeername(int fd, struct sockaddr* name, int* namelen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_getpeername(fd_table.w32_ios[fd], name, namelen);
|
||||
@ -222,7 +223,7 @@ w32_getpeername(int fd, struct sockaddr* name, int* namelen) {
|
||||
|
||||
int
|
||||
w32_listen(int fd, int backlog) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_listen(fd_table.w32_ios[fd], backlog);
|
||||
@ -230,7 +231,7 @@ w32_listen(int fd, int backlog) {
|
||||
|
||||
int
|
||||
w32_bind(int fd, const struct sockaddr *name, int namelen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_bind(fd_table.w32_ios[fd], name, namelen);
|
||||
@ -238,7 +239,7 @@ w32_bind(int fd, const struct sockaddr *name, int namelen) {
|
||||
|
||||
int
|
||||
w32_connect(int fd, const struct sockaddr* name, int namelen) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_connect(fd_table.w32_ios[fd], name, namelen);
|
||||
@ -246,7 +247,7 @@ w32_connect(int fd, const struct sockaddr* name, int namelen) {
|
||||
|
||||
int
|
||||
w32_recv(int fd, void *buf, size_t len, int flags) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_recv(fd_table.w32_ios[fd], buf, len, flags);
|
||||
@ -254,7 +255,7 @@ w32_recv(int fd, void *buf, size_t len, int flags) {
|
||||
|
||||
int
|
||||
w32_send(int fd, const void *buf, size_t len, int flags) {
|
||||
debug3("fd:%d", fd);
|
||||
|
||||
CHECK_FD(fd);
|
||||
return socketio_send(fd_table.w32_ios[fd], buf, len, flags);
|
||||
}
|
||||
@ -262,7 +263,7 @@ w32_send(int fd, const void *buf, size_t len, int flags) {
|
||||
|
||||
int
|
||||
w32_shutdown(int fd, int how) {
|
||||
debug3("fd:%d how:%d", fd, how);
|
||||
debug2("shutdown - fd:%d how:%d", fd, how);
|
||||
CHECK_FD(fd);
|
||||
CHECK_SOCK_IO(fd_table.w32_ios[fd]);
|
||||
return socketio_shutdown(fd_table.w32_ios[fd], how);
|
||||
@ -271,7 +272,7 @@ w32_shutdown(int fd, int how) {
|
||||
int
|
||||
w32_socketpair(int domain, int type, int sv[2]) {
|
||||
errno = ENOTSUP;
|
||||
debug("ERROR:%d", errno);
|
||||
debug("socketpair - ERROR not supported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -302,8 +303,8 @@ w32_pipe(int *pfds) {
|
||||
fd_table_set(pio[1], write_index);
|
||||
pfds[0] = read_index;
|
||||
pfds[1] = write_index;
|
||||
debug("read end: handle:%p, io:%p, fd:%d", pio[0]->handle, pio[0], read_index);
|
||||
debug("write end: handle:%p, io:%p, fd:%d", pio[1]->handle, pio[1], write_index);
|
||||
debug("pipe - read end: handle:%p, io:%p, fd:%d", pio[0]->handle, pio[0], read_index);
|
||||
debug("pipe - write end: handle:%p, io:%p, fd:%d", pio[1]->handle, pio[1], write_index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -322,7 +323,8 @@ w32_open(const char *pathname, int flags, ...) {
|
||||
|
||||
pio->type = FILE_FD;
|
||||
fd_table_set(pio, min_index);
|
||||
debug("handle:%p, io:%p, fd:%d", pio->handle, pio, min_index);
|
||||
debug("open - handle:%p, io:%p, fd:%d", pio->handle, pio, min_index);
|
||||
debug3("open - path:%s", pathname);
|
||||
return min_index;
|
||||
}
|
||||
|
||||
@ -363,6 +365,7 @@ int
|
||||
w32_mkdir(const char *pathname, unsigned short mode) {
|
||||
return _mkdir(pathname);
|
||||
}
|
||||
|
||||
int
|
||||
w32_isatty(int fd) {
|
||||
if ((fd < 0) || (fd > MAX_FDS - 1) || fd_table.w32_ios[fd] == NULL) {
|
||||
@ -377,7 +380,7 @@ w32_fdopen(int fd, const char *mode) {
|
||||
errno = 0;
|
||||
if ((fd < 0) || (fd > MAX_FDS - 1) || fd_table.w32_ios[fd] == NULL) {
|
||||
errno = EBADF;
|
||||
debug("bad fd: %d", fd);
|
||||
debug("fdopen - ERROR bad fd: %d", fd);
|
||||
return NULL;
|
||||
}
|
||||
return fileio_fdopen(fd_table.w32_ios[fd], mode);
|
||||
@ -390,7 +393,7 @@ w32_close(int fd) {
|
||||
CHECK_FD(fd);
|
||||
pio = fd_table.w32_ios[fd];
|
||||
|
||||
debug("io:%p, type:%d, fd:%d, table_index:%d", pio, pio->type, fd,
|
||||
debug("close - io:%p, type:%d, fd:%d, table_index:%d", pio, pio->type, fd,
|
||||
pio->table_index);
|
||||
fd_table_clear(pio->table_index);
|
||||
if ((pio->type == SOCK_FD))
|
||||
@ -420,7 +423,7 @@ w32_fcntl(int fd, int cmd, ... /* arg */) {
|
||||
return 0;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
debug("ERROR: cmd:%d", cmd);
|
||||
debug("fcntl - ERROR not supported cmd:%d", cmd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -446,19 +449,19 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
|
||||
if (fds > MAX_FDS) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR: fds: %d", fds);
|
||||
debug("select - ERROR: invalid fds: %d", fds);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!readfds && !writefds) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR: null fd_sets");
|
||||
debug("select - ERROR: null fd_sets");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (exceptfds) {
|
||||
errno = EOPNOTSUPP;
|
||||
debug("ERROR: exceptfds not supported");
|
||||
debug("select - ERROR: exceptfds not supported");
|
||||
abort();
|
||||
return -1;
|
||||
}
|
||||
@ -482,7 +485,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
/* if none of input fds are set return error */
|
||||
if (in_set_fds == 0) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR: empty fd_sets");
|
||||
debug("select - ERROR: empty fd_sets");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -499,7 +502,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
if ((fd_table.w32_ios[i]->type == SOCK_FD)
|
||||
&& (fd_table.w32_ios[i]->internal.state == SOCK_LISTENING)) {
|
||||
if (num_events == SELECT_EVENT_LIMIT) {
|
||||
debug("ERROR: max #events reached for select");
|
||||
debug("select - ERROR: max #events breach");
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -513,7 +516,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
if ((fd_table.w32_ios[i]->type == SOCK_FD)
|
||||
&& (fd_table.w32_ios[i]->internal.state == SOCK_CONNECTING)) {
|
||||
if (num_events == SELECT_EVENT_LIMIT) {
|
||||
debug("ERROR: max #events reached for select");
|
||||
debug("select - ERROR: max #events reached for select");
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@ -555,7 +558,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
|
||||
if (timeout != NULL) {
|
||||
if (timeout_ms < ticks_spent) {
|
||||
debug("select timing out");
|
||||
debug("select - timing out");
|
||||
break;
|
||||
}
|
||||
time_rem = timeout_ms - (ticks_spent & 0xffffffff);
|
||||
@ -588,7 +591,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
}
|
||||
|
||||
if (out_ready_fds == 0)
|
||||
debug2("wait ended without any IO completion, looping again");
|
||||
debug3("select - wait ended without any IO completion, looping again");
|
||||
|
||||
}
|
||||
|
||||
@ -604,6 +607,7 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
|
||||
FD_CLR(i, writefds);
|
||||
|
||||
|
||||
debug3("select - returning %d", out_ready_fds);
|
||||
return out_ready_fds;
|
||||
|
||||
}
|
||||
@ -617,7 +621,7 @@ w32_dup(int oldfd) {
|
||||
CHECK_FD(oldfd);
|
||||
if (oldfd > STDERR_FILENO) {
|
||||
errno = EOPNOTSUPP;
|
||||
debug("ERROR: dup only supported for std io, fd:%d", oldfd);
|
||||
debug("dup - ERROR: supports only std io, fd:%d", oldfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -627,7 +631,7 @@ w32_dup(int oldfd) {
|
||||
src = GetStdHandle(fd_table.w32_ios[oldfd]->std_handle);
|
||||
if (src == INVALID_HANDLE_VALUE) {
|
||||
errno = EINVAL;
|
||||
debug("ERROR: unable to get underlying handle for std fd:%d", oldfd);
|
||||
debug("dup - ERROR: unable to get underlying handle for std fd:%d", oldfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -635,13 +639,13 @@ w32_dup(int oldfd) {
|
||||
target = CreateFileA("CONIN$", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (target == INVALID_HANDLE_VALUE) {
|
||||
errno = EOTHER;
|
||||
debug("ERROR: CreateFile CONIN$ failed, error:%d", GetLastError());
|
||||
debug("dup - ERROR: CreateFile CONIN$ :%d", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!DuplicateHandle(GetCurrentProcess(), src, GetCurrentProcess(), &target, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
|
||||
errno = EOTHER;
|
||||
debug("ERROR: Duplicated Handle failed, error:%d", GetLastError());
|
||||
debug("dup - ERROR: DuplicatedHandle() :%d", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -649,7 +653,7 @@ w32_dup(int oldfd) {
|
||||
if (pio == NULL) {
|
||||
CloseHandle(target);
|
||||
errno = ENOMEM;
|
||||
debug("ERROR: %d", errno);
|
||||
debug("dup - ERROR: %d", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -664,7 +668,7 @@ int
|
||||
w32_dup2(int oldfd, int newfd) {
|
||||
CHECK_FD(oldfd);
|
||||
errno = EOPNOTSUPP;
|
||||
debug("ERROR: dup2 is not implemented yet");
|
||||
debug("dup2 - ERROR: not implemented yet");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user