Author: mturk Date: Mon Aug 8 14:26:24 2011 New Revision: 1154972 URL: http://svn.apache.org/viewvc?rev=1154972&view=rev Log: Axe debug printf's
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h?rev=1154972&r1=1154971&r2=1154972&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h Mon Aug 8 14:26:24 2011 @@ -407,6 +407,15 @@ int AcrIpcRead(LPIPCSOCK pSocket, void *pData, int nSize); /** + * Initialize IPC system. + * + * @notice This function must be called before any other + * IPC function. + */ +int +AcrIpcInit(void); + +/** * Write the data. * @param pSocket the socket to use. * @param pData input data buffer Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c?rev=1154972&r1=1154971&r2=1154972&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c Mon Aug 8 14:26:24 2011 @@ -145,10 +145,10 @@ AcquireMutex(HANDLE hMutex) int AcrIpcInit() { - static int inited = 0; + static volatile long inited = 0; - if (inited++) - return WSAEALREADY; + if (InterlockedExchangeAdd(&inited, 1) != 0) + return 0; /* Catch some common immutable variables * which won't change for the process life-time. */ @@ -330,7 +330,8 @@ AcrIpcServerClose(LPIPCSERVER sp) if (sp->nConnections != 0) { /* Should never happen [tm] */ - printf("[server] Found %d active. Should be zero\n", sp->nConnections); + fprintf(stderr, "[server] Found %d active. Should be zero\n", sp->nConnections); + fflush(stderr); } SAFE_CLOSE_HANDLE(sp->hAcceptSema); SAFE_CLOSE_HANDLE(sp->hAcceptSync); @@ -423,7 +424,6 @@ AcrIoBufMap(HANDLE hMap, DWORD dwSize) if (MapViewOfFileEx(hMap, FILE_MAP_ALL_ACCESS, 0, 0, dwSize, pBase + dwSize) != 0) return pBase; /* Mapped two in a row */ UnmapViewOfFile(pBase); - printf("[debug] Mapping again %d\n", nAttempts); /* Yield the processor */ SwitchToThread(); pBase = VirtualAlloc(0, 2 * dwSize, MEM_RESERVE, PAGE_READWRITE); @@ -504,10 +504,8 @@ retry: return 0; } again: - printf("[server] Waiting on accept ...\n"); /* Wait for a client connect */ ws = WaitForSingleObject(sp->hAcceptSync, nTimeout); - printf("[server] Waiting on accept : %d\n", ws); switch (ws) { case WAIT_OBJECT_0: /* Client signaled there is a new @@ -522,7 +520,6 @@ again: case WAIT_TIMEOUT: ApcIpcServerUnref(sp); /* Timeout */ - printf("[server] accept timeout\n"); if (nTimeout == 0) SetLastError(WSAEWOULDBLOCK); else @@ -536,7 +533,6 @@ again: default: ApcIpcServerUnref(sp); /* Error! */ - printf("[server] illegal accept wait result\n"); SetLastError(rc); return 0; break; @@ -548,7 +544,6 @@ again: */ if ((nTimeout == -1) || ((nTimeup > 0) && (nTimeup > GetCurrentMilliseconds()))) { ReleaseMutex(sp->hAcceptLock); - printf("[server] Retrying ...\n"); goto again; } ApcIpcServerUnref(sp); @@ -565,7 +560,6 @@ again: ReleaseMutex(sp->hAcceptLock); a = sp->s->a + i; - printf("[server] Processing accept for client %d:%d\n", i, a->nStatus); hClientMeta = DW2H(a->nClientMeta); if (a->nStatus == 0 || hClientMeta == 0) { InterlockedExchange(&a->nStatus, WSAENOTSOCK); @@ -573,7 +567,6 @@ again: * to the caller? */ if ((nTimeout == -1) || ((nTimeup > 0) && (nTimeup > GetCurrentMilliseconds()))) { - printf("[server] Restarting ...\n"); goto retry; } rc = WSAETIMEDOUT; @@ -737,22 +730,16 @@ again: case WAIT_OBJECT_1: case WAIT_ABANDONED_1: ReleaseMutex(cp->rp->hProcessLock); - printf("[client] Server died\n"); rc = WSAECONNREFUSED; break; case WAIT_TIMEOUT: - printf("[client] Timeout!\n"); if (nTimeout == 0) rc = WSAEWOULDBLOCK; else rc = WSAETIMEDOUT; break; - case WAIT_FAILED: - rc = GetLastError(); - printf("[client] Wait failed %d\n", rc); - break; default: - printf("[client] Unexpected result %d\n", rc); + rc = GetLastError(); break; } if (rc != 0) @@ -770,7 +757,6 @@ again: */ ReleaseMutex(cp->rp->hAcceptLock); if ((nTimeout == -1) || ((nTimeup > 0) && (nTimeup > GetCurrentMilliseconds()))) { - printf("[client] No free connection slots. retrying\n"); goto again; } /* Timeout occured */ @@ -831,10 +817,7 @@ again: goto failed; cp->c->nBufferMap[1] = H2DW(hDuplicate); } - printf("[client] Connected to %d\n", cp->rp->s->dwProcessId); SetEvent(cp->rp->hAcceptSync); - /* Not needed any more */ - printf("[client] Waiting for ack\n"); if (nTimeout != -1 && nTimeout != 0) { /* Update timeout with the time we spend inside processing so far */ @@ -862,19 +845,13 @@ again: case WAIT_OBJECT_1: case WAIT_ABANDONED_1: ReleaseMutex(cp->rp->hProcessLock); - printf("[client] Server died\n"); rc = WSAECONNREFUSED; break; case WAIT_TIMEOUT: - printf("[client] Timeout!\n"); rc = WSAETIMEDOUT; break; - case WAIT_FAILED: - rc = GetLastError(); - printf("[client] Wait failed %d\n", rc); - break; default: - printf("[client] Unexpected result %d\n", rc); + rc = GetLastError(); break; } if (rc == 0) @@ -893,7 +870,6 @@ again: ApcIpcUnref(cp); return 0; } - printf("client] connection rejected. recycling\n"); goto cleanup; failed: rc = GetLastError(); @@ -1009,7 +985,6 @@ AcrIpcSocketClose(LPIPCSOCK cp) InterlockedDecrement(&cp->sp->nConnections); LeaveCriticalSection(&gSynchronized); } - printf("[close] Refcount=%d\n", cp->nReferences); /* Depending if the socket was inside a blocking * call this mignt not actually free the socket. * However the call to unref in the blocking call will Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java?rev=1154972&r1=1154971&r2=1154972&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java (original) +++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java Mon Aug 8 14:26:24 2011 @@ -31,7 +31,7 @@ public class TestIpc extends Assert private static final String ipcname = "acrIpcs23"; - private void parentInit() + private void parentInit(boolean childWait) throws Exception { try { @@ -39,8 +39,13 @@ public class TestIpc extends Assert } catch (Exception x) { // Ignore } - Semaphore s = Semaphore.create(semname, 1); - assertNotNull(s); + Semaphore s = Semaphore.create(semname, 0); + assertNotNull(s); + if (childWait) { + System.out.println("[parent] Waiting for the child to attach" ); + System.out.flush(); + s.acquire(); + } } private void childInit() @@ -59,26 +64,26 @@ public class TestIpc extends Assert step *= 2; } assertNotNull(s); - s.acquire(); + s.release(); } @Test(groups = { "ipcs.parent" }) public void ipcSimpleAccept() throws Exception - { + { System.out.println("[parent] Creating ipc server" ); System.out.flush(); - parentInit(); IpcServerEndpoint ss = new IpcServerEndpoint(); IpcEndpointAddress sa = new IpcEndpointAddress(ipcname); ss.configureBlocking(false); ss.bind(sa); System.out.println("[parent] Waiting for a child to connect"); System.out.flush(); + parentInit(false); IpcEndpoint ec = ss.accept(); assertNotNull(ec); System.out.println("[parent] Accepted."); - System.out.flush(); + System.out.flush(); ss.close(); ec.close(); System.out.println("[parent] Done."); @@ -90,7 +95,7 @@ public class TestIpc extends Assert throws Exception { childInit(); - + System.out.println("[child] Connecting"); System.out.flush(); IpcEndpointAddress sa = new IpcEndpointAddress(ipcname); @@ -98,7 +103,7 @@ public class TestIpc extends Assert IpcEndpoint cs = new IpcEndpoint(); cs.connect(sa); assertTrue(cs.isBlocking()); - cs.close(); + cs.close(); System.out.println("[child] Done."); System.out.flush(); }