diff options
author | Stefan Metzmacher <metze@samba.org> | 2010-09-29 09:37:05 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2010-09-29 10:49:40 +0200 |
commit | 45e3e54e087120009a79cb70b3377e63cfc0033e (patch) | |
tree | 845d298447d89fa5679d34f6693c9866c3b1c504 /testprogs | |
parent | 6c0a4b6477df872d03696faec1b786ad3352a7ca (diff) | |
download | samba-45e3e54e087120009a79cb70b3377e63cfc0033e.tar.gz |
midltests: support for fragmented RPC traffic
metze
Diffstat (limited to 'testprogs')
-rw-r--r-- | testprogs/win32/midltests/midltests_tcp.c | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/testprogs/win32/midltests/midltests_tcp.c b/testprogs/win32/midltests/midltests_tcp.c index 25c45843893..3046f6debc6 100644 --- a/testprogs/win32/midltests/midltests_tcp.c +++ b/testprogs/win32/midltests/midltests_tcp.c @@ -232,6 +232,44 @@ static void change_packet(const char *ctx, BOOL ndr64, } } +static int sock_pending(SOCKET s) +{ + int ret, error; + int value = 0; + int len; + + ret = ioctlsocket(s, FIONREAD, &value); + if (ret == -1) { + return ret; + } + + if (ret != 0) { + /* this should not be reached */ + return -1; + } + + if (value != 0) { + return value; + } + + error = 0; + len = sizeof(error); + + /* + * if no data is available check if the socket is in error state. For + * dgram sockets it's the way to return ICMP error messages of + * connected sockets to the caller. + */ + ret = getsockopt(s, SOL_SOCKET, SO_ERROR, (char *)&error, &len); + if (ret == -1) { + return ret; + } + if (error != 0) { + return -1; + } + return 0; +} + DWORD WINAPI NDRProxyThread(LPVOID lpParameter) { struct NDRProxyThreadCtx *p = (struct NDRProxyThreadCtx *)lpParameter; @@ -241,12 +279,19 @@ DWORD WINAPI NDRProxyThread(LPVOID lpParameter) int ret = -1; BYTE buf[5840]; + Sleep(250); + + ret = sock_pending(p->InSocket); + if (ret == 0) { + goto out; + } + r = recv(p->InSocket, buf, sizeof(buf), 0); if (r <= 0) { ret = WSAGetLastError(); printf("%s: recv(in) failed[%d][%d]\n", p->ctx->name, r, ret); fflush(stdout); - goto next; + goto stop; } change_packet(p->ctx->name, p->ctx->ndr64, buf, r); @@ -255,11 +300,17 @@ DWORD WINAPI NDRProxyThread(LPVOID lpParameter) dump_packet(p->ctx->name, "in => out", buf, r); fflush(stdout); +out: s = send(p->OutSocket, buf, r, 0); if (s <= 0) { ret = WSAGetLastError(); printf("%s: send(out) failed[%d][%d]\n", p->ctx->name, s, ret); fflush(stdout); + goto stop; + } + + ret = sock_pending(p->OutSocket); + if (ret == 0) { goto next; } @@ -268,7 +319,7 @@ DWORD WINAPI NDRProxyThread(LPVOID lpParameter) ret = WSAGetLastError(); printf("%s: recv(out) failed[%d][%d]\n", p->ctx->name, r, ret); fflush(stdout); - goto next; + goto stop; } dump_packet(p->ctx->name, "out => in", buf, r); @@ -279,11 +330,12 @@ DWORD WINAPI NDRProxyThread(LPVOID lpParameter) ret = WSAGetLastError(); printf("%s: send(in) failed[%d][%d]\n", p->ctx->name, s, ret); fflush(stdout); - goto next; + goto stop; } - - } next: + continue; + } +stop: closesocket(p->InSocket); closesocket(p->OutSocket); |