Author: mturk
Date: Sat Jul 9 06:25:30 2011
New Revision: 1144604
URL: http://svn.apache.org/viewvc?rev=1144604&view=rev
Log:
Check if the socket pid process is running befor attempting to connect
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c?rev=1144604&r1=1144603&r2=1144604&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Sat Jul
9 06:25:30 2011
@@ -144,7 +144,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
{
int rc;
char ssbuf[32];
- HANDLE sfh = 0;
+ HANDLE sfp;
DWORD pid, port;
struct sockaddr_in sa;
int sas = ISIZEOF(sa);
@@ -153,7 +153,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
wls_fd_t *wd = J2P(fp, wls_fd_t *);
if (AcrReadFileDataA(ca->hostname, ssbuf, &bsz) == 0) {
- rc = GetLastError();
+ rc = ACR_GET_OS_ERROR();
SOCKADDR_RELEASE(cb, ca);
return rc;
}
@@ -161,11 +161,19 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
if (sscanf(ssbuf, "%u %u", &pid, &port) != 2) {
/* Bad format ?
*/
- rc = ACR_ENOTSOCK;
- goto finally;
+ return ACR_ENOTSOCK;
}
- /* TODO: Check if process is running
- */
+ sfp = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
+ if (IS_INVALID_HANDLE(sfp))
+ return ACR_GET_OS_ERROR();
+ if (GetExitCodeProcess(sfp, &rc)) {
+ if (rc != STILL_ACTIVE) {
+ /* Process has been terminated */
+ CloseHandle(sfp);
+ return ACR_ENOTSOCK;
+ }
+ }
+ CloseHandle(sfp);
sa.sin_port = htons((u_short)port);
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
@@ -186,8 +194,6 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
}
}
}
-finally:
- SAFE_CLOSE_HANDLE(sfh);
return rc;
}