Cleanups to the socket code, its still not perfect, but much more usable now
git-svn-id: file:///home/svn/framework3/trunk@7750 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
0961ce3523
commit
792724c3f3
|
@ -391,6 +391,9 @@ DWORD _channel_packet_completion_routine(Remote *remote, Packet *packet,
|
|||
Channel *channel = channel_find_by_id(channelId);
|
||||
DWORD res = ERROR_NOT_FOUND;
|
||||
|
||||
|
||||
dprintf( "[CHANNEL] _channel_packet_completion_routine. channel=0x%08X method=%s", channel, method );
|
||||
|
||||
// If the channel was not found and it isn't an open request, return failure
|
||||
if (!channel && strcmp(method, "core_channel_open"))
|
||||
return ERROR_NOT_FOUND;
|
||||
|
@ -665,6 +668,8 @@ DWORD channel_close(Channel *channel, Remote *remote, Tlv *addend,
|
|||
realRequestCompletion = &requestCompletion;
|
||||
}
|
||||
|
||||
dprintf( "[CHANNEL] channel_close. channel=0x%08X completion=0x%.8x", channel, completionRoutine );
|
||||
|
||||
// Transmit the packet with the supplied completion routine, if any.
|
||||
res = packet_transmit(remote, request, realRequestCompletion);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "list.h"
|
||||
|
||||
|
||||
#ifdef DEBUGTRACE
|
||||
#define dprintf(...) real_dprintf(__VA_ARGS__)
|
||||
#else
|
||||
|
|
|
@ -86,16 +86,33 @@ static DWORD tcp_channel_client_local_notify(Remote *remote,
|
|||
FD_SET(ctx->fd, &set);
|
||||
|
||||
// Read data from the client connection
|
||||
if (((bytesRead = recv(ctx->fd, buf, sizeof(buf), 0))
|
||||
== SOCKET_ERROR) ||
|
||||
(bytesRead == 0))
|
||||
{
|
||||
channel_close(ctx->channel, ctx->remote, NULL, 0, NULL);
|
||||
bytesRead = recv(ctx->fd, buf, sizeof(buf), 0);
|
||||
|
||||
// Not sure why we get these with pending data
|
||||
if(bytesRead == SOCKET_ERROR) {
|
||||
printf( "[TCP] tcp_channel_client_local_notify. [error] channel=0x%08X read=0x%.8x (ignored)", ctx->channel, bytesRead );
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bytesRead == 0) {
|
||||
dprintf( "[TCP] tcp_channel_client_local_notify. [closed] channel=0x%08X read=0x%.8x", ctx->channel, bytesRead );
|
||||
|
||||
// Set the native channel operations context to NULL
|
||||
channel_set_native_io_context(ctx->channel, NULL);
|
||||
|
||||
// Free the context
|
||||
free_tcp_client_context(ctx);
|
||||
|
||||
// Stop processing
|
||||
break;
|
||||
}
|
||||
else if (ctx->channel)
|
||||
|
||||
if (ctx->channel) {
|
||||
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=0x%08X read=0x%.8x", ctx->channel, bytesRead );
|
||||
channel_write(ctx->channel, ctx->remote, NULL, 0, buf, bytesRead, 0);
|
||||
} else {
|
||||
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=<invalid> read=0x%.8x", bytesRead );
|
||||
}
|
||||
|
||||
} while (select(0, &set, NULL, NULL, &tv) > 0);
|
||||
|
||||
|
@ -270,17 +287,23 @@ VOID free_socket_context(SocketContext *ctx)
|
|||
dprintf( "[TCP] free_socket_context. ctx=0x%08X", ctx );
|
||||
|
||||
// Close the socket and notification handle
|
||||
if (ctx->fd)
|
||||
if (ctx->fd){
|
||||
closesocket(ctx->fd);
|
||||
ctx->fd = NULL;
|
||||
}
|
||||
if (ctx->notify)
|
||||
{
|
||||
scheduler_remove_waitable(ctx->notify);
|
||||
|
||||
WSACloseEvent(ctx->notify);
|
||||
// XXX: Leaving this triggers an invalid handle in another thread?
|
||||
// WSACloseEvent(ctx->notify);
|
||||
ctx->notify = NULL;
|
||||
}
|
||||
|
||||
if (ctx->channel)
|
||||
if (ctx->channel) {
|
||||
channel_close(ctx->channel, ctx->remote, NULL, 0, NULL);
|
||||
ctx->channel = NULL;
|
||||
}
|
||||
|
||||
// Free the context
|
||||
free(ctx);
|
||||
|
|
Loading…
Reference in New Issue