You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/07/21 20:02:09 UTC
svn commit: r1149286 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.msc.in os/win32/arch_opts.h os/win32/init.c os/win32/ipcsock.c
os/win32/ipcsock.h os/win32/util.c
Author: mturk
Date: Thu Jul 21 18:02:08 2011
New Revision: 1149286
URL: http://svn.apache.org/viewvc?rev=1149286&view=rev
Log:
Add win32 ipcsock stub files
Added:
commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c (with props)
commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1149286&r1=1149285&r2=1149286&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Jul 21 18:02:08 2011
@@ -82,6 +82,7 @@ WIN32_SOURCES=\
$(TOPDIR)\os\win32\execmem.c \
$(TOPDIR)\os\win32\inetsock.c \
$(TOPDIR)\os\win32\init.c \
+ $(TOPDIR)\os\win32\ipcsock.c \
$(TOPDIR)\os\win32\localsock.c \
$(TOPDIR)\os\win32\os.c \
$(TOPDIR)\os\win32\path.c \
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h?rev=1149286&r1=1149285&r2=1149286&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_opts.h Thu Jul 21 18:02:08 2011
@@ -273,6 +273,8 @@ int AcrDrainSocket(SOCKET sd);
int AcrNonblock(SOCKET sd, int on);
int AcrWaitIO(SOCKET sd, int timeout, int events);
char *AcrReadFileDataA(const char *name, char *sbuf, int *len);
+int AcrCreateUuid(LPBYTE);
+void AcrUuidToStringW(LPWSTR out, LPBYTE id);
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz);
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t siz);
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c?rev=1149286&r1=1149285&r2=1149286&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c Thu Jul 21 18:02:08 2011
@@ -32,6 +32,7 @@ HANDLE _heap_handle = 0
LPSYSTEM_INFO acr_osinf = &osinf;
LPOSVERSIONINFOEXA acr_osver = &osver;
HANDLE acr_raised_event = 0;
+HANDLE acr_alived_mutex = 0;
typedef struct tlsd_t
{
@@ -156,6 +157,8 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
acr_osver->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
GetVersionExA((LPOSVERSIONINFOA)acr_osver);
acr_raised_event = CreateEvent(0, TRUE, FALSE, 0);
+ acr_alived_mutex = CreateMutex(GetSaWithNullDacl(0, JNI_FALSE), TRUE, 0);
+
if (IS_INVALID_HANDLE(acr_raised_event))
return JNI_ERR;
if (AcrLoadLateDLLs() != 0)
Added: 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=1149286&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c Thu Jul 21 18:02:08 2011
@@ -0,0 +1,48 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/jnitypes.h"
+#include "acr/error.h"
+#include "acr/memory.h"
+#include "acr/netapi.h"
+#include "acr/unsafe.h"
+#include "acr/port.h"
+#include "ipcsock.h"
+#include "arch_opts.h"
+#include "arch_sync.h"
+
+#define SOCKADDR_CAST(BA) \
+ (acr_sockaddr_t *)AcrGetArrayCritical(env, (BA))
+#define SOCKADDR_RELEASE(BA, SA) \
+ AcrReleaseArrayCritical(env, (BA), (SA))
+
+/* Never destroyed
+ * Susessfull Wait on that handle means the process died.
+ * This is single instance Mutex which either client or server duplicates.
+ */
+extern HANDLE acr_alived_mutex;
+static HANDLE current_process;
+static DWORD current_pid;
+
+ACR_NET_EXPORT(void, IpcEndpoint, init0)(JNI_STDARGS)
+{
+ /* Catch some common immutable variables
+ * which won't change for the process life-time.
+ */
+ current_process = GetCurrentProcess();
+ current_pid = GetCurrentProcessId();
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h?rev=1149286&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h Thu Jul 21 18:02:08 2011
@@ -0,0 +1,231 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/stdtypes.h"
+
+#ifndef _IPCSOCK_H_
+#define _IPCSOCK_H_
+
+/*
+
+Inter Process Communication Socket
+==================================
+
+Custom communication channel for windows.
+It uses shared memory for data transfer between multiple
+processes. Like with unix sockets the name represents
+the channel of communication having one server and
+multiple clients.
+
+Server side:
+
+Server creates a shared memory with header and data buffer.
+Its main purpose is to accept the client connections.
+The buffer size reflects the socket api listen function backlog
+and should be big enough to handle the burst load.
+
+Inside header, server puts its sync object handle data as
+DWORD so that the size is equal regarless of 32 or 64 bit version.
+
+Client side:
+
+Client creates a shared memory with the header and data
+for read and write buffers. By default it uses the pagesize
+(64K) for both header and r/w buffers. This means that client
+should not go beyond 32K for a single read/write size
+for optimal performance.
+
+Connection procedure first opens the server acceptor shared memory
+with the name that represents the address and duplicates the
+sync objects into his address space. It then locks the server
+and when it gots the lock, it writes its connection info into the
+first free accept buffer and unlocks the server so others can
+continue connect operation. Server at that time gets the signal
+from the newly connected client, locks the accept storage and pulls
+first record as part of accept call. That record becomes the
+initial data for establisking the connection from the server side.
+
+*/
+
+/**
+ * [shm] Written by the client to the accept data queue
+ */
+typedef struct sipc_accept_rec_t
+{
+ DWORD pid; /* Process that is connecting
+ */
+ DWORD shm; /* Client shared memory mapping.
+ * This handle is already duplicated
+ * to the server process when written
+ * by the client.
+ * Server uses MapViewOfFile to maps
+ * this memory into his address space.
+ */
+} sipc_accept_rec_t;
+
+/**
+ * [shm] Main server header
+ */
+typedef struct sipc_server_header_t
+{
+ DWORD pid; /* Server process id
+ */
+ DWORD mutex; /* Process temination mutex
+ * Client duplicates that handle to monitor
+ * the server death.
+ */
+ DWORD areq; /* Accept request semaphore.
+ * When ever there is accept() call
+ * it increments the acount and releases the semaphore
+ * by one. It then waits for connect requested event
+ * which client signals after he updates the record.
+ */
+ DWORD creq; /* Event on which server waits on accept.
+ * Client duplicates that handle and signals after
+ * he writes the connection record.
+ */
+ int backlog; /* Backlog size or number of records
+ */
+ volatile long acount; /* Number of currently queued accept() calls.
+ * Incremented by the accept call.
+ * Decremented when the connect record is pulled from
+ * the queue.
+ */
+ volatile long ccount; /* Number of currently queued connect() calls.
+ * Incremented by the client after he gots the
+ * areq semaphore. Client must not continue the
+ * connect procedure if the result of atomic increment
+ * is backlog.
+ * Server decrements that value after connect record
+ * is removed from the queue.
+ */
+ volatile long wridx; /* Index in r[] where the client will
+ * write the next client connect record.
+ * Before written it is incremented.
+ * if the atomic increment returns backlog
+ * it has to be set to 1 using atomic exchange.
+ */
+ sipc_accept_rec_t r[0]; /* Accept record circle queue.
+ * Client which got gemaphore always writes
+ * at wridx.
+ * Must be the last struct entry.
+ * For 64K page size it should be
+ * (65536 - 32) / 8 == 8188
+ * This means that the backlog is 8190 max
+ * for a 64K page size.
+ */
+} sipc_server_header_t;
+
+/**
+ * [shm] Client header data
+ * This is initial data in the clients shared memory set-up
+ * before connect call.
+ */
+typedef struct sipc_client_header_t
+{
+ DWORD mutex; /* Client's process mutex.
+ * This is ususally never destroyed
+ * for the process life-time.
+ * Signal on that mutex means that
+ * the client's process has died.
+ */
+ DWORD aack; /* Accept acknowledge signal.
+ * Client blocks on this signal
+ * after he writes the connection record.
+ * Server sets this event after it creates
+ * the connection or fails and it that case
+ * the error is set to non-zero.
+ */
+ DWORD sync[4]; /* Read sync events
+ * They are write events on the server side.
+ * First signals that there are data to read
+ * and second read readines.
+ * Write sync events
+ * They are read events on the server side.
+ * First signals that there are data written
+ * and second write ready.
+ */
+ DWORD rdlen; /* Size of the read buffer */
+ DWORD wrlen; /* Size of the write buffer */
+ DWORD error; /* Accept status set by server
+ * so that client can get the
+ * error code if accept is refused.
+ */
+ DWORD sessionid; /* Session id number set by the server
+ * when the connection is established.
+ */
+
+} sipc_client_header_t;
+
+/**
+ * [shm] Read/Write buffer data
+ */
+typedef struct sipc_data_buffer_t
+{
+ volatile long rd; /* Currently reading from the buffer */
+ volatile long wr; /* Currently writting to the buffer */
+ volatile long pos; /* Current position in data buffer */
+ volatile long len; /* Current data len from pos */
+ BYTE d[0];
+} sipc_data_buffer_t;
+
+/** Client Connection event mappings
+ */
+#define CC_RD 0 /* Client has Read the Data.
+ * Set by the client after read call
+ * finished to indicate that some data was
+ * read. The server waits on that event when his
+ * send buffer is full.
+ */
+#define CC_RTR 1 /* Client is Ready To Receive data.
+ * Client blocks on that event when there is no
+ * data in the read queue.
+ */
+#define CC_TD 2 /* Client has Transmit the Data.
+ * Set by the client after write call finishes
+ * to indicate that some data was written.
+ * Server blocks on this event when the receive
+ * buffer is empty.
+ */
+#define CC_RTT 3 /* Client is Ready To Transmit data.
+ * Client blocks on that event when the write
+ * buffer is full and server has not read the data.
+ * after server reads the data it signals this
+ * evet so client can continue with writting.
+ */
+
+/**
+ * Server Sonnection event mappings
+ * Those are the same events as for client
+ * but their idexes have different meaning.
+ */
+#define SC_RD 3 /* Server has Read the Data.
+ * Signal the client to continue writting.
+ */
+#define SC_RTR 2 /* Block if read buffer is empty.
+ * Client sets the CC_TD to indicate that he wrote
+ * some data.
+ */
+#define SC_TD 1 /* Server has wrote the data.
+ * Set the client CC_RTR event to singlal the client
+ * to continue reading.
+ */
+#define SC_RTT 0 /* Wait if the write buffer is full
+ * Client sets CC_RD when he read some data so
+ * we can continue writting.
+ */
+
+#endif /* _IPCSOCK_H_ */
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c?rev=1149286&r1=1149285&r2=1149286&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/util.c Thu Jul 21 18:02:08 2011
@@ -21,7 +21,11 @@
#include "acr/time.h"
#include "arch_opts.h"
+#include <rpc.h>
+
#define PIPE_FMT "\\\\.\\pipe\\00000000-0000-0000-0000-000000000000"
+#define GLOB_FMT "Global\\00000000-0000-0000-0000-000000000000"
+
static volatile LONG _pipe_id = 23;
/* This is the helper code to resolve late bound entry points
* missing from one or more releases of the Win32 API
@@ -600,3 +604,40 @@ failed:
ACR_SET_OS_ERROR(rc);
return 0;
}
+
+int
+AcrCreateUuid(LPBYTE d)
+{
+ for (;;) {
+ int i;
+ if (FAILED(UuidCreateSequential((UUID *)d))) {
+ /* This should never happen */
+ return ACR_EGENERAL;
+ }
+ for (i = 8; i < 16; i++) {
+ if (d[i] != 0)
+ break;
+ }
+ /* Last 8 bytes are all zero. Try again */
+ }
+ return 0;
+}
+
+static const wchar_t basis16[] = L"0123456789abcdef";
+
+#define HI_NIBBLE_HEXW(a) basis16[(a) >> 4]
+#define LO_NIBBLE_HEXW(a) basis16[(a) & 0x0F]
+
+void
+AcrUuidToStringW(LPWSTR out, LPBYTE id)
+{
+ int i;
+
+ for (i = 0; i < 16; i++) {
+ if (i == 4 || i == 6 || i == 8 || i == 10)
+ *(out++) = L'-';
+ *(out++) = HI_NIBBLE_HEXW(id[i]);
+ *(out++) = LO_NIBBLE_HEXW(id[i]);
+ }
+ *out = L'\0';
+}