*/
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,
/* ------------------------------------------------------------------------ */
+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;
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
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());
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.
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 {
(long*)(&err) ); /* Return code */
}
RpcExcept(1) {
- handle_exception(RpcExceptionCode());
+ err = handle_exception(RpcExceptionCode(), ptspdata);
}
RpcEndExcept;
}
-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;
}
*/
cc_int32 ccapi_connect(const struct tspdata* tsp) {
BOOL bListen = TRUE;
- char* endpoint = NULL;
HANDLE replyEvent = 0;
RPC_STATUS status = FALSE;
char* uuid = NULL;
/* 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);