summaryrefslogtreecommitdiffstats
path: root/src/ccapi/lib/win/ccapi_os_ipc.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/ccapi/lib/win/ccapi_os_ipc.cxx')
-rw-r--r--src/ccapi/lib/win/ccapi_os_ipc.cxx120
1 files changed, 65 insertions, 55 deletions
diff --git a/src/ccapi/lib/win/ccapi_os_ipc.cxx b/src/ccapi/lib/win/ccapi_os_ipc.cxx
index 7359eb0bad..8cc9d03bd4 100644
--- a/src/ccapi/lib/win/ccapi_os_ipc.cxx
+++ b/src/ccapi/lib/win/ccapi_os_ipc.cxx
@@ -64,7 +64,7 @@ SECURITY_ATTRIBUTES sa = { 0 };
*/
cc_int32 ccapi_connect(const struct tspdata* tsp);
-static DWORD handle_exception(DWORD code);
+static DWORD handle_exception(DWORD code, struct tspdata* ptspdata);
extern "C" {
cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
@@ -75,12 +75,46 @@ cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
/* ------------------------------------------------------------------------ */
+extern "C" cc_int32 cci_os_ipc_process_init (void) {
+ RPC_STATUS status;
+
+ opts.cMinCalls = 1;
+ opts.cMaxCalls = 20;
+ if (!isNT()) {
+ status = RpcServerRegisterIf(ccs_reply_ServerIfHandle, // interface
+ NULL, // MgrTypeUuid
+ NULL); // MgrEpv; null means use default
+ }
+ else {
+ status = RpcServerRegisterIfEx(ccs_reply_ServerIfHandle, // interface
+ NULL, // MgrTypeUuid
+ NULL, // MgrEpv; 0 means default
+ RPC_IF_ALLOW_SECURE_ONLY,
+ opts.cMaxCalls,
+ NULL); // No security callback.
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ status = RpcServerRegisterAuthInfo(0, // server principal
+ RPC_C_AUTHN_WINNT,
+ 0,
+ 0 );
+ cci_check_error(status);
+ }
+
+ return status; // ugh. needs translation
+}
+
+/* ------------------------------------------------------------------------ */
+
extern "C" cc_int32 cci_os_ipc_thread_init (void) {
cc_int32 err = ccNoError;
struct tspdata* ptspdata;
- HANDLE replyEvent;
+ HANDLE replyEvent = NULL;
UUID __RPC_FAR uuid;
- unsigned char __RPC_FAR* uuidString = NULL;
+ RPC_CSTR __RPC_FAR uuidString = NULL;
+ char* endpoint = NULL;
if (!GetTspData(GetTlsIndex(), &ptspdata)) return ccErrNoMem;
@@ -91,10 +125,18 @@ extern "C" cc_int32 cci_os_ipc_thread_init (void) {
err = cci_check_error(UuidCreate(&uuid)); // Get a UUID
if (err == RPC_S_OK) { // Convert to string
err = UuidToString(&uuid, &uuidString);
+ cci_check_error(err);
}
if (!err) { // Save in thread local storage
tspdata_setUUID(ptspdata, uuidString);
+ endpoint = clientEndpoint((const char *)uuidString);
+ err = RpcServerUseProtseqEp((RPC_CSTR)"ncalrpc",
+ opts.cMaxCalls,
+ (RPC_CSTR)endpoint,
+ sa.lpSecurityDescriptor); // SD
+ cci_check_error(err);
}
+
#if 0
cci_debug_printf("%s UUID:<%s>", __FUNCTION__, tspdata_getUUID(ptspdata));
#endif
@@ -109,6 +151,17 @@ extern "C" cc_int32 cci_os_ipc_thread_init (void) {
replyEvent = createThreadEvent((char*)uuidString, REPLY_SUFFIX);
}
+ if (!err) {
+ static bool bListening = false;
+ if (!bListening) {
+ err = RpcServerListen(opts.cMinCalls,
+ opts.cMaxCalls,
+ TRUE);
+ cci_check_error(err);
+ }
+ bListening = err == 0;
+ }
+
if (replyEvent) tspdata_setReplyEvent(ptspdata, replyEvent);
else err = cci_check_error(GetLastError());
@@ -159,6 +212,10 @@ extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
sst = tspdata_getSST (ptspdata);
uuid = tspdata_getUUID(ptspdata);
+ // Initialize old CCAPI if necessary:
+ if (!err) if (!Init:: Initialized()) err = cci_check_error(Init:: Initialize( ));
+ if (!err) if (!Client::Initialized()) err = cci_check_error(Client::Initialize(0));
+
// The lazy connection to the server has been put off as long as possible!
// ccapi_connect starts listening for replies as an RPC server and then
// calls ccs_rpc_connect.
@@ -183,10 +240,6 @@ extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
CcAutoLock* a = 0;
CcAutoLock::Start(a, Client::sLock);
- // Initialize old CCAPI if necessary:
- if (!err) if (!Init:: Initialized()) err = cci_check_error(Init:: Initialize( ));
- if (!err) if (!Client::Initialized()) err = cci_check_error(Client::Initialize(0));
-
// New code using new RPC procedures for sending the data and receiving a reply:
if (!err) {
RpcTryExcept {
@@ -209,7 +262,7 @@ extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
(long*)(&err) ); /* Return code */
}
RpcExcept(1) {
- handle_exception(RpcExceptionCode());
+ err = handle_exception(RpcExceptionCode(), ptspdata);
}
RpcEndExcept;
}
@@ -247,12 +300,13 @@ extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
-static DWORD handle_exception(DWORD code) {
+static DWORD handle_exception(DWORD code, struct tspdata* ptspdata) {
cci_debug_printf("%s code %u; ccs_request_IfHandle:0x%X", __FUNCTION__, code, ccs_request_IfHandle);
if ( (code == RPC_S_SERVER_UNAVAILABLE) || (code == RPC_S_INVALID_BINDING) ) {
- Client::Reconnect(0);
+ Client::Cleanup();
+ tspdata_setConnected(ptspdata, FALSE);
}
- return 4;
+ return code;
}
@@ -262,7 +316,6 @@ static DWORD handle_exception(DWORD code) {
*/
cc_int32 ccapi_connect(const struct tspdata* tsp) {
BOOL bListen = TRUE;
- char* endpoint = NULL;
HANDLE replyEvent = 0;
RPC_STATUS status = FALSE;
char* uuid = NULL;
@@ -275,56 +328,13 @@ cc_int32 ccapi_connect(const struct tspdata* tsp) {
/* Build complete RPC uuid using previous CCAPI implementation: */
replyEvent = tspdata_getReplyEvent(tsp);
uuid = tspdata_getUUID(tsp);
- endpoint = clientEndpoint(uuid);
- cci_debug_printf("%s Registering endpoint %s", __FUNCTION__, endpoint);
opts.cMinCalls = 1;
opts.cMaxCalls = 20;
opts.fDontWait = TRUE;
- if (!status) {
- status = RpcServerUseProtseqEp((RPC_CSTR)"ncalrpc",
- opts.cMaxCalls,
- (RPC_CSTR)endpoint,
- sa.lpSecurityDescriptor); // SD
- cci_check_error(status);
- }
-
- if (!status) {
- status = RpcServerRegisterAuthInfo(0, // server principal
- RPC_C_AUTHN_WINNT,
- 0,
- 0 );
- cci_check_error(status);
- }
-
cci_debug_printf("%s is listening ...", __FUNCTION__);
- if (!status) {
- if (!isNT()) {
- status = RpcServerRegisterIf(ccs_reply_ServerIfHandle, // interface
- NULL, // MgrTypeUuid
- NULL); // MgrEpv; null means use default
- }
- else {
- status = RpcServerRegisterIfEx(ccs_reply_ServerIfHandle,// interface
- NULL, // MgrTypeUuid
- NULL, // MgrEpv; 0 means default
- RPC_IF_ALLOW_SECURE_ONLY,
- opts.cMaxCalls,
- NULL); // No security callback.
- }
-
- cci_check_error(status);
-
- if (!status) {
- status = RpcServerListen(opts.cMinCalls,
- opts.cMaxCalls,
- TRUE);
- cci_check_error(status);
- }
- }
-
// Clear replyEvent so we can detect when a reply to our connect request has been received:
ResetEvent(replyEvent);