From d18f28560600c12af047af16bccaba6a3bc5f757 Mon Sep 17 00:00:00 2001 From: Trent Daniel Date: Fri, 13 Dec 2024 14:29:26 -0500 Subject: [PATCH 1/4] EBP-383: Added compile directive to solClient.h so that when the Go API links against CCSMP, it treats all opaque pointers as uintptrs (effectively longs) instead of as void pointers, except for solClient_opaquePtr_pt. I couldn't figure out how to get around solClient_opaquePtr_pt because certain CCSMP functions like solClient_msg_getBinaryAttachmentPtr require a pointer to an opaque pointer. This was all done to avoid the cgo runtime from panicking when it does a runtime check of a C/Go boundary and believes that the 'void *' type that the opaque pointers used to be typedef'd to was an unpinned pointer. As mentioned, the change to the typdef of opaque pointers in solClient.h will prevent the cgo runtime from panicking since it will evaluate the opaque pointers as longs/ints instead of unpinned references. It's unclear whether or not the solClient_opaquePtr_pt will become a problem in the future, but it is actually pointing to data whereas the other solClient_opaque*_pt types are not, which the cgo runtime should be able to discern. The other changes made in this commit were in response to the typdef change, and isolating more memory allocation of configuration structs like the sessionCreateFuncInfo to C in order to mitigate the risk of bad references being accessed by CCSMP. --- internal/ccsmp/ccsmp_container.go | 1 + internal/ccsmp/ccsmp_core.go | 23 ++++++------ internal/ccsmp/ccsmp_endpoint_permissions.go | 1 + .../ccsmp/ccsmp_endpoint_prop_generated.go | 1 + internal/ccsmp/ccsmp_flow.go | 1 + internal/ccsmp/ccsmp_flow_event_generated.go | 1 + internal/ccsmp/ccsmp_flow_prop_generated.go | 1 + internal/ccsmp/ccsmp_global_prop_generated.go | 1 + internal/ccsmp/ccsmp_helper.c | 35 +++++++++++++++++++ internal/ccsmp/ccsmp_helper.h | 9 +++++ internal/ccsmp/ccsmp_log_level_generated.go | 1 + internal/ccsmp/ccsmp_message.go | 1 + internal/ccsmp/ccsmp_message_tracing.go | 1 + internal/ccsmp/ccsmp_return_code_generated.go | 1 + internal/ccsmp/ccsmp_rmid.go | 1 + .../ccsmp/ccsmp_session_event_generated.go | 1 + .../ccsmp/ccsmp_session_prop_generated.go | 1 + .../ccsmp/ccsmp_session_stats_rx_generated.go | 1 + .../ccsmp/ccsmp_session_stats_tx_generated.go | 1 + internal/ccsmp/cgo_helpers.go | 1 + .../ccsmp_endpoint_prop_generator.go | 2 +- .../generator/ccsmp_flow_event_generator.go | 2 +- .../generator/ccsmp_flow_prop_generator.go | 2 +- .../generator/ccsmp_global_prop_generator.go | 2 +- .../generator/ccsmp_log_level_generator.go | 2 +- .../generator/ccsmp_return_code_generator.go | 2 +- .../ccsmp_session_event_generator.go | 2 +- .../generator/ccsmp_session_prop_generator.go | 2 +- .../ccsmp_session_stats_generator.go | 2 +- internal/ccsmp/includes_darwin_amd64.go | 2 +- internal/ccsmp/includes_darwin_arm64.go | 2 +- internal/ccsmp/includes_linux_amd64.go | 2 +- internal/ccsmp/includes_linux_arm64.go | 2 +- .../ccsmp/lib/include/solclient/solClient.h | 13 +++++++ internal/impl/message/message_test.go | 20 +++++------ .../impl/message/outbound_message_impl.go | 2 +- .../request_reply_message_publisher_impl.go | 4 +-- 37 files changed, 111 insertions(+), 38 deletions(-) diff --git a/internal/ccsmp/ccsmp_container.go b/internal/ccsmp/ccsmp_container.go index fe2d33a..ac7434a 100644 --- a/internal/ccsmp/ccsmp_container.go +++ b/internal/ccsmp/ccsmp_container.go @@ -24,6 +24,7 @@ import ( ) /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include "solclient/solClient.h" diff --git a/internal/ccsmp/ccsmp_core.go b/internal/ccsmp/ccsmp_core.go index 7aa5e60..113b8ca 100644 --- a/internal/ccsmp/ccsmp_core.go +++ b/internal/ccsmp/ccsmp_core.go @@ -19,6 +19,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include @@ -52,6 +53,9 @@ import ( // Reexport of various CCSMP types +type SolClientOpaquePointerType = C.uintptr_t +const SolClientOpaquePointerInvalidValue = SolClientOpaquePointerType(0) + // SolClientContextPt is assigned a value type SolClientContextPt = C.solClient_opaqueContext_pt @@ -250,7 +254,7 @@ type SolClientSession struct { // SetMessageCallback sets the message callback to use func (session *SolClientSession) SetMessageCallback(callback SolClientMessageCallback) error { - if session == nil || session.pointer == nil { + if session == nil || session.pointer == SolClientOpaquePointerInvalidValue { return fmt.Errorf("could not set message receive callback for nil session") } if callback == nil { @@ -263,7 +267,7 @@ func (session *SolClientSession) SetMessageCallback(callback SolClientMessageCal // SetReplyMessageCallback sets the message callback to use func (session *SolClientSession) SetReplyMessageCallback(callback SolClientReplyMessageCallback) error { - if session == nil || session.pointer == nil { + if session == nil || session.pointer == SolClientOpaquePointerInvalidValue { return fmt.Errorf("could not set message receive callback for nil session") } if callback == nil { @@ -276,7 +280,7 @@ func (session *SolClientSession) SetReplyMessageCallback(callback SolClientReply // SetEventCallback sets the event callback to use func (session *SolClientSession) SetEventCallback(callback SolClientSessionEventCallback) error { - if session == nil || session.pointer == nil { + if session == nil || session.pointer == SolClientOpaquePointerInvalidValue { return fmt.Errorf("could not set event callback for nil session") } if callback == nil { @@ -300,8 +304,7 @@ func SolClientInitialize(props []string) *SolClientErrorInfoWrapper { func SolClientContextCreate() (context *SolClientContext, err *SolClientErrorInfoWrapper) { var contextP SolClientContextPt solClientErrorInfo := handleCcsmpError(func() SolClientReturnCode { - var contextFuncInfo C.solClient_context_createFuncInfo_t - return C.solClient_context_create(C.SOLCLIENT_CONTEXT_PROPS_DEFAULT_WITH_CREATE_THREAD, &contextP, &contextFuncInfo, 24) + return C.SessionContextCreate(C.SOLCLIENT_CONTEXT_PROPS_DEFAULT_WITH_CREATE_THREAD, &contextP) }) if solClientErrorInfo != nil { return nil, solClientErrorInfo @@ -322,14 +325,10 @@ func (context *SolClientContext) SolClientSessionCreate(properties []string) (se sessionPropsP, sessionPropertiesFreeFunction := ToCArray(properties, true) defer sessionPropertiesFreeFunction() - var sessionFuncInfo C.solClient_session_createFuncInfo_t - sessionFuncInfo.rxMsgInfo.callback_p = (C.solClient_session_rxMsgCallbackFunc_t)(unsafe.Pointer(C.defaultMessageReceiveCallback)) - sessionFuncInfo.rxMsgInfo.user_p = nil - sessionFuncInfo.eventInfo.callback_p = (C.solClient_session_eventCallbackFunc_t)(unsafe.Pointer(C.eventCallback)) - sessionFuncInfo.eventInfo.user_p = nil - solClientErrorInfo := handleCcsmpError(func() SolClientReturnCode { - return C.solClient_session_create(sessionPropsP, context.pointer, &sessionP, &sessionFuncInfo, (C.size_t)(unsafe.Sizeof(sessionFuncInfo))) + return C.SessionCreate(sessionPropsP, + context.pointer, + &sessionP) }) if solClientErrorInfo != nil { return nil, solClientErrorInfo diff --git a/internal/ccsmp/ccsmp_endpoint_permissions.go b/internal/ccsmp/ccsmp_endpoint_permissions.go index 5a2f637..0fb925b 100644 --- a/internal/ccsmp/ccsmp_endpoint_permissions.go +++ b/internal/ccsmp/ccsmp_endpoint_permissions.go @@ -17,6 +17,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_endpoint_prop_generated.go b/internal/ccsmp/ccsmp_endpoint_prop_generated.go index 0689859..1bc3ffd 100644 --- a/internal/ccsmp/ccsmp_endpoint_prop_generated.go +++ b/internal/ccsmp/ccsmp_endpoint_prop_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_endpoint_prop_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_flow.go b/internal/ccsmp/ccsmp_flow.go index efa271c..b345b41 100644 --- a/internal/ccsmp/ccsmp_flow.go +++ b/internal/ccsmp/ccsmp_flow.go @@ -25,6 +25,7 @@ import ( ) /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include diff --git a/internal/ccsmp/ccsmp_flow_event_generated.go b/internal/ccsmp/ccsmp_flow_event_generated.go index 1abc3ed..9b83de6 100644 --- a/internal/ccsmp/ccsmp_flow_event_generated.go +++ b/internal/ccsmp/ccsmp_flow_event_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_flow_event_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_flow_prop_generated.go b/internal/ccsmp/ccsmp_flow_prop_generated.go index 6138c35..a4db657 100644 --- a/internal/ccsmp/ccsmp_flow_prop_generated.go +++ b/internal/ccsmp/ccsmp_flow_prop_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_flow_prop_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_global_prop_generated.go b/internal/ccsmp/ccsmp_global_prop_generated.go index f8180c4..ce71cff 100644 --- a/internal/ccsmp/ccsmp_global_prop_generated.go +++ b/internal/ccsmp/ccsmp_global_prop_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_global_prop_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_helper.c b/internal/ccsmp/ccsmp_helper.c index 431a093..919cc55 100644 --- a/internal/ccsmp/ccsmp_helper.c +++ b/internal/ccsmp/ccsmp_helper.c @@ -24,12 +24,17 @@ solClient_rxMsgCallback_returnCode_t messageReceiveCallback(solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void *user_p); +solClient_rxMsgCallback_returnCode_t +defaultMessageReceiveCallback(solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void *user_p); + solClient_rxMsgCallback_returnCode_t requestResponseReplyMessageReceiveCallback(solClient_opaqueSession_pt opaqueSession_p, solClient_opaqueMsg_pt msg_p, void *user_p); solClient_rxMsgCallback_returnCode_t flowMessageReceiveCallback(solClient_opaqueFlow_pt opaqueFlow_p, solClient_opaqueMsg_pt msg_p, void *user_p); +void eventCallback(solClient_opaqueSession_pt opaqueSession_p, solClient_session_eventCallbackInfo_pt eventInfo_p, void *user_p); + void flowEventCallback(solClient_opaqueFlow_pt opaqueFlow_p, solClient_flow_eventCallbackInfo_pt eventInfo_p, void *user_p); solClient_returnCode_t @@ -53,6 +58,36 @@ solClientgo_msg_isRequestReponseMsg(solClient_opaqueMsg_pt msg_p, char **correla return SOLCLIENT_OK; } +solClient_returnCode_t +SessionCreate( solClient_propertyAray_pt sessionPropsP, + solClient_opaqueContext_pt contextP, + solClient_opaqueSession_pt *opaqueSession_p) +{ + /* allocate the session create struct */ + solClient_session_createFuncInfo_t sessionCreateFuncInfo; + sessionCreateFuncInfo.rxMsgInfo.callback_p = NULL; + sessionCreateFuncInfo.eventInfo.callback_p = (solClient_session_eventCallbackFunc_t)eventCallback; + sessionCreateFuncInfo.eventInfo.user_p = NULL; + // allocate thse struct fields to NULL too + sessionCreateFuncInfo.rxInfo.user_p = NULL; + sessionCreateFuncInfo.rxInfo.callback_p = NULL; + + return solClient_session_create(sessionPropsP, contextP, opaqueSession_p, &sessionCreateFuncInfo, sizeof(sessionCreateFuncInfo)); +} + +solClient_returnCode_t +SessionContextCreate( solClient_propertyArray_pt contextPropsP, + solClient_opaqueContext_pt *contextP) +{ + /* allocate the session context create struct to NULL */ + solClient_conte3xt_createFuncInfo_t contextCreateFuncInfo; + contextCreateFuncInfo.regFdInfo.user_p = NULL; + contextCreateFuncInfo.regFdInfo.regFdFunc_p = NULL; + contextCreateFuncInfo.regFdInfo.unregFdFunc_p = NULL; + + return solClient_context_create(contextPropsP, contextP, &contextCreateFuncInfo, sizeof(contextCreateFuncInfo)); +} + solClient_returnCode_t SessionFlowCreate( solClient_opaqueSession_pt opaqueSession_p, solClient_propertyArray_pt flowPropsP, diff --git a/internal/ccsmp/ccsmp_helper.h b/internal/ccsmp/ccsmp_helper.h index 04f2d8e..d588914 100644 --- a/internal/ccsmp/ccsmp_helper.h +++ b/internal/ccsmp/ccsmp_helper.h @@ -44,6 +44,15 @@ typedef struct solClient_errorInfo_wrapper * operating systems are supported, this may need to change to a more complex * definition. */ +solClient_returnCode_t SessionCreate( + solClient_propertyArray_pt sessionPropsP, + solClient_opaqueContext_pt contextP, + solClient_opaqueSession_pt *opaqueSession_p); + +solClient_returnCode_t SessionContextCreate( + solClient_propertyArray_pt contextPropsP, + solClient_opaqueContext_pt *contextP); + solClient_returnCode_t SessionFlowCreate( solClient_opaqueSession_pt opaqueSession_p, solClient_propertyArray_pt flowPropsP, diff --git a/internal/ccsmp/ccsmp_log_level_generated.go b/internal/ccsmp/ccsmp_log_level_generated.go index a8f65af..3548d74 100644 --- a/internal/ccsmp/ccsmp_log_level_generated.go +++ b/internal/ccsmp/ccsmp_log_level_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_log_level_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_message.go b/internal/ccsmp/ccsmp_message.go index 28ca15a..0152281 100644 --- a/internal/ccsmp/ccsmp_message.go +++ b/internal/ccsmp/ccsmp_message.go @@ -17,6 +17,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include diff --git a/internal/ccsmp/ccsmp_message_tracing.go b/internal/ccsmp/ccsmp_message_tracing.go index 13dbbee..b416130 100644 --- a/internal/ccsmp/ccsmp_message_tracing.go +++ b/internal/ccsmp/ccsmp_message_tracing.go @@ -17,6 +17,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include diff --git a/internal/ccsmp/ccsmp_return_code_generated.go b/internal/ccsmp/ccsmp_return_code_generated.go index b6f137e..ec947ab 100644 --- a/internal/ccsmp/ccsmp_return_code_generated.go +++ b/internal/ccsmp/ccsmp_return_code_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_return_code_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_rmid.go b/internal/ccsmp/ccsmp_rmid.go index 0700e59..48cddd5 100644 --- a/internal/ccsmp/ccsmp_rmid.go +++ b/internal/ccsmp/ccsmp_rmid.go @@ -17,6 +17,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include diff --git a/internal/ccsmp/ccsmp_session_event_generated.go b/internal/ccsmp/ccsmp_session_event_generated.go index 1418497..637412f 100644 --- a/internal/ccsmp/ccsmp_session_event_generated.go +++ b/internal/ccsmp/ccsmp_session_event_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_session_event_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_session_prop_generated.go b/internal/ccsmp/ccsmp_session_prop_generated.go index c19abec..ce4185d 100644 --- a/internal/ccsmp/ccsmp_session_prop_generated.go +++ b/internal/ccsmp/ccsmp_session_prop_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_session_prop_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_session_stats_rx_generated.go b/internal/ccsmp/ccsmp_session_stats_rx_generated.go index 1e1fee4..3cef0b0 100644 --- a/internal/ccsmp/ccsmp_session_stats_rx_generated.go +++ b/internal/ccsmp/ccsmp_session_stats_rx_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_session_stats_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/ccsmp_session_stats_tx_generated.go b/internal/ccsmp/ccsmp_session_stats_tx_generated.go index 5c14f4f..7810bbe 100644 --- a/internal/ccsmp/ccsmp_session_stats_tx_generated.go +++ b/internal/ccsmp/ccsmp_session_stats_tx_generated.go @@ -19,6 +19,7 @@ package ccsmp // Code generated by ccsmp_session_stats_generator.go via go generate. DO NOT EDIT. /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include "solclient/solClient.h" */ import "C" diff --git a/internal/ccsmp/cgo_helpers.go b/internal/ccsmp/cgo_helpers.go index 378c3ac..8cdafb8 100644 --- a/internal/ccsmp/cgo_helpers.go +++ b/internal/ccsmp/cgo_helpers.go @@ -17,6 +17,7 @@ package ccsmp /* +#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO #include #include diff --git a/internal/ccsmp/generator/ccsmp_endpoint_prop_generator.go b/internal/ccsmp/generator/ccsmp_endpoint_prop_generator.go index 7390c7a..e446d8f 100644 --- a/internal/ccsmp/generator/ccsmp_endpoint_prop_generator.go +++ b/internal/ccsmp/generator/ccsmp_endpoint_prop_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_endpoint_prop_generated.go" -const header string = "package ccsmp\n// Code generated by ccsmp_endpoint_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n// Code generated by ccsmp_endpoint_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientEndpointProp" const definePrefix string = "SOLCLIENT_ENDPOINT_PROP" diff --git a/internal/ccsmp/generator/ccsmp_flow_event_generator.go b/internal/ccsmp/generator/ccsmp_flow_event_generator.go index 20f2bed..cff026d 100644 --- a/internal/ccsmp/generator/ccsmp_flow_event_generator.go +++ b/internal/ccsmp/generator/ccsmp_flow_event_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_flow_event_generated.go" -const header string = "package ccsmp\n\n// Code generated by ccsmp_flow_event_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n\n// Code generated by ccsmp_flow_event_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientFlowEvent" const typeName string = "SolClientFlowEvent" diff --git a/internal/ccsmp/generator/ccsmp_flow_prop_generator.go b/internal/ccsmp/generator/ccsmp_flow_prop_generator.go index a2a8d00..c294a5a 100644 --- a/internal/ccsmp/generator/ccsmp_flow_prop_generator.go +++ b/internal/ccsmp/generator/ccsmp_flow_prop_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_flow_prop_generated.go" -const header string = "package ccsmp\n// Code generated by ccsmp_flow_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n// Code generated by ccsmp_flow_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientFlowProp" const definePrefix string = "SOLCLIENT_FLOW_PROP" diff --git a/internal/ccsmp/generator/ccsmp_global_prop_generator.go b/internal/ccsmp/generator/ccsmp_global_prop_generator.go index 7d487a7..22f6f58 100644 --- a/internal/ccsmp/generator/ccsmp_global_prop_generator.go +++ b/internal/ccsmp/generator/ccsmp_global_prop_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_global_prop_generated.go" -const header string = "package ccsmp\n// Code generated by ccsmp_global_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n// Code generated by ccsmp_global_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientGlobalProp" const definePrefix string = "SOLCLIENT_GLOBAL_PROP" diff --git a/internal/ccsmp/generator/ccsmp_log_level_generator.go b/internal/ccsmp/generator/ccsmp_log_level_generator.go index d30d50d..d9e79a5 100644 --- a/internal/ccsmp/generator/ccsmp_log_level_generator.go +++ b/internal/ccsmp/generator/ccsmp_log_level_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_log_level_generated.go" -const header string = "package ccsmp\n\n// Code generated by ccsmp_log_level_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n\n// Code generated by ccsmp_log_level_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientLogLevel" const typeName string = "SolClientLogLevel" diff --git a/internal/ccsmp/generator/ccsmp_return_code_generator.go b/internal/ccsmp/generator/ccsmp_return_code_generator.go index 738e68b..4fd94a4 100644 --- a/internal/ccsmp/generator/ccsmp_return_code_generator.go +++ b/internal/ccsmp/generator/ccsmp_return_code_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_return_code_generated.go" -const header string = "package ccsmp\n\n// Code generated by ccsmp_return_code_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n\n// Code generated by ccsmp_return_code_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientReturnCode" const typeName string = "SolClientReturnCode" diff --git a/internal/ccsmp/generator/ccsmp_session_event_generator.go b/internal/ccsmp/generator/ccsmp_session_event_generator.go index de7bfa1..f49482c 100644 --- a/internal/ccsmp/generator/ccsmp_session_event_generator.go +++ b/internal/ccsmp/generator/ccsmp_session_event_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_session_event_generated.go" -const header string = "package ccsmp\n\n// Code generated by ccsmp_session_event_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n\n// Code generated by ccsmp_session_event_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientSessionEvent" const typeName string = "SolClientSessionEvent" diff --git a/internal/ccsmp/generator/ccsmp_session_prop_generator.go b/internal/ccsmp/generator/ccsmp_session_prop_generator.go index d72b97a..c9a3ba2 100644 --- a/internal/ccsmp/generator/ccsmp_session_prop_generator.go +++ b/internal/ccsmp/generator/ccsmp_session_prop_generator.go @@ -31,7 +31,7 @@ import ( // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. const outputFile string = "ccsmp_session_prop_generated.go" -const header string = "package ccsmp\n// Code generated by ccsmp_session_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n// Code generated by ccsmp_session_prop_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const namePrefix string = "SolClientSessionProp" const definePrefix string = "SOLCLIENT_SESSION_PROP" diff --git a/internal/ccsmp/generator/ccsmp_session_stats_generator.go b/internal/ccsmp/generator/ccsmp_session_stats_generator.go index 725e36c..72b67a0 100644 --- a/internal/ccsmp/generator/ccsmp_session_stats_generator.go +++ b/internal/ccsmp/generator/ccsmp_session_stats_generator.go @@ -30,7 +30,7 @@ import ( // It can be invoked by running `go generate` in the the ccsmp directory. // The environment variable SOLCLIENT_H must be set to the absolute path to project_root/lib//include/solclient/solClient.h. -const header string = "package ccsmp\n// Code generated by ccsmp_session_stats_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" +const header string = "package ccsmp\n// Code generated by ccsmp_session_stats_generator.go via go generate. DO NOT EDIT.\n\n\n/*\n#cgo CFLAGS: -DSOLCLIENT_PSPLUS_GO\n#include \"solclient/solClient.h\"\n*/\nimport \"C\"\nconst (\n" const footer string = ")\n" const outputFilePrefix string = "ccsmp_session_stats_" diff --git a/internal/ccsmp/includes_darwin_amd64.go b/internal/ccsmp/includes_darwin_amd64.go index 5715b54..62d58cd 100644 --- a/internal/ccsmp/includes_darwin_amd64.go +++ b/internal/ccsmp/includes_darwin_amd64.go @@ -18,7 +18,7 @@ package ccsmp /* // specific flags for darwin static builds in C -#cgo CFLAGS: -I${SRCDIR}/lib/include +#cgo CFLAGS: -I${SRCDIR}/lib/include -DSOLCLIENT_PSPLUS_GO #cgo LDFLAGS: -L/usr/local/opt/openssl/lib ${SRCDIR}/lib/darwin/libsolclient.a -lssl -lcrypto -framework Kerberos */ import "C" diff --git a/internal/ccsmp/includes_darwin_arm64.go b/internal/ccsmp/includes_darwin_arm64.go index fbb01e5..3d2a743 100644 --- a/internal/ccsmp/includes_darwin_arm64.go +++ b/internal/ccsmp/includes_darwin_arm64.go @@ -18,7 +18,7 @@ package ccsmp /* // specific flags for darwin static builds in C -#cgo CFLAGS: -I${SRCDIR}/lib/include +#cgo CFLAGS: -I${SRCDIR}/lib/include -DSOLCLIENT_PSPLUS_GO #cgo LDFLAGS: -L/opt/homebrew/opt/openssl/lib ${SRCDIR}/lib/darwin/libsolclient.a -lssl -lcrypto -framework Kerberos */ import "C" diff --git a/internal/ccsmp/includes_linux_amd64.go b/internal/ccsmp/includes_linux_amd64.go index d107cd5..b97c0e4 100644 --- a/internal/ccsmp/includes_linux_amd64.go +++ b/internal/ccsmp/includes_linux_amd64.go @@ -18,7 +18,7 @@ package ccsmp /* // specific flags for linux static builds in C -#cgo CFLAGS: -I${SRCDIR}/lib/include +#cgo CFLAGS: -I${SRCDIR}/lib/include -DSOLCLIENT_PSPLUS_GO #cgo LDFLAGS: ${SRCDIR}/lib/linux_amd64/libsolclient.a -lm -ldl -lpthread -lrt #include diff --git a/internal/ccsmp/includes_linux_arm64.go b/internal/ccsmp/includes_linux_arm64.go index 652fc4e..3cbb96b 100644 --- a/internal/ccsmp/includes_linux_arm64.go +++ b/internal/ccsmp/includes_linux_arm64.go @@ -18,7 +18,7 @@ package ccsmp /* // specific flags for linux static builds in C -#cgo CFLAGS: -I${SRCDIR}/lib/include +#cgo CFLAGS: -I${SRCDIR}/lib/include -DSOLCLIENT_PSPLUS_GO #cgo LDFLAGS: ${SRCDIR}/lib/linux_arm64/libsolclient.a -lm -ldl -lpthread -lrt #include diff --git a/internal/ccsmp/lib/include/solclient/solClient.h b/internal/ccsmp/lib/include/solclient/solClient.h index 2e7fb3c..f8692a1 100644 --- a/internal/ccsmp/lib/include/solclient/solClient.h +++ b/internal/ccsmp/lib/include/solclient/solClient.h @@ -18,6 +18,7 @@ #include #include #include +#include #endif #if defined(__cplusplus) @@ -568,6 +569,17 @@ typedef char ** solClient_propertyArray_pt; /**< pointer to an array of s * is returned from solClient_context_create() when a Context is created, and it is passed into other * APIs that operate on a Context. */ +#if defined(SOLCLIENT_PSPLUS_GO) +typedef uintptr_t solClient_opaqueContext_pt; /**< An opaque pointer to a processing Context. */ +typedef uintptr_t solClient_opaqueSession_pt; /**< An opaque pointer to a Session. */ +typedef uintptr_t solClient_opaqueFlow_pt; /**< An opaque pointer to a Flow. */ +typedef uintptr_t solClient_opaqueMsg_pt; /**< An opaque pointer to a message. */ +typedef uintptr_t solClient_opaqueContainer_pt; /**< An opaque pointer to a container (such as a map or stream). */ +typedef uintptr_t solClient_opaqueDatablock_pt; /**< An opaque pointer to a data block. */ +typedef uintptr_t solClient_opaqueTransactedSession_pt; /**< An opaque pointer to a Transacted Session. */ +/*@}*/ +typedef void * *solClient_opaquePointer_pt; /**< An opaque pointer to a pointer */ +#else typedef void *solClient_opaqueContext_pt; /**< An opaque pointer to a processing Context. */ typedef void *solClient_opaqueSession_pt; /**< An opaque pointer to a Session. */ typedef void *solClient_opaqueFlow_pt; /**< An opaque pointer to a Flow. */ @@ -577,6 +589,7 @@ typedef void *solClient_opaqueDatablock_pt; /**< An opaqu typedef void *solClient_opaqueTransactedSession_pt; /**< An opaque pointer to a Transacted Session. */ /*@}*/ typedef void * *solClient_opaquePointer_pt; /**< An opaque pointer to a pointer */ +#endif /** * @enum solClient_destinationType diff --git a/internal/impl/message/message_test.go b/internal/impl/message/message_test.go index cd62cf8..9235c13 100644 --- a/internal/impl/message/message_test.go +++ b/internal/impl/message/message_test.go @@ -29,7 +29,7 @@ func TestOutboundMessageFree(t *testing.T) { if err != nil { t.Error("did not expect error, got " + err.Error()) } - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -39,7 +39,7 @@ func TestOutboundMessageFree(t *testing.T) { if !msg.IsDisposed() { t.Error("IsDisposed returned false, expected true") } - if msg.messagePointer != nil { + if msg.messagePointer != ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected MessagePointer to be freed and set to nil, it was not") } } @@ -50,7 +50,7 @@ func TestInboundMessageFree(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -60,7 +60,7 @@ func TestInboundMessageFree(t *testing.T) { if !msg.IsDisposed() { t.Error("IsDisposed returned false, expected true") } - if msg.messagePointer != nil { + if msg.messagePointer != ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected MessagePointer to be freed and set to nil, it was not") } } @@ -85,7 +85,7 @@ func TestSetCreationTraceContext(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -145,7 +145,7 @@ func TestGetCreationTraceContext(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -208,7 +208,7 @@ func TestSetTransportTraceContext(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -268,7 +268,7 @@ func TestGetTransportTraceContext(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -323,7 +323,7 @@ func TestSetBaggage(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { @@ -357,7 +357,7 @@ func TestGetBaggage(t *testing.T) { t.Error("did not expect error, got " + ccsmpErr.GetMessageAsString()) } msg := NewInboundMessage(msgP, false) - if msg.messagePointer == nil { + if msg.messagePointer == ccsmp.SolClientOpaquePointerInvalidValue { t.Error("expected message pointer to not be nil") } if msg.IsDisposed() { diff --git a/internal/impl/message/outbound_message_impl.go b/internal/impl/message/outbound_message_impl.go index c7071fe..33a56bd 100644 --- a/internal/impl/message/outbound_message_impl.go +++ b/internal/impl/message/outbound_message_impl.go @@ -166,7 +166,7 @@ func SetAsReplyMessage(message *OutboundMessageImpl, replyToDestination string, // GetOutboundMessagePointer function func GetOutboundMessagePointer(message *OutboundMessageImpl) ccsmp.SolClientMessagePt { if message == nil { - return nil + return ccsmp.SolClientOpaquePointerInvalidValue } return message.messagePointer } diff --git a/internal/impl/publisher/request_reply_message_publisher_impl.go b/internal/impl/publisher/request_reply_message_publisher_impl.go index 3231d6d..9e49eb4 100644 --- a/internal/impl/publisher/request_reply_message_publisher_impl.go +++ b/internal/impl/publisher/request_reply_message_publisher_impl.go @@ -877,12 +877,12 @@ func (publisher *requestReplyMessagePublisherImpl) handleReplyMessage(msgP core. defer publisher.rxLock.Unlock() corEntry, ok := publisher.requestCorrelationMap[correlationID] if !ok { - publisher.logger.Debug(fmt.Sprintf("Received reply message[%p] with correlationID[%s] without correlation entry for publisher", msgP, correlationID)) + publisher.logger.Debug(fmt.Sprintf("Received reply message[0x%x] with correlationID[%s] without correlation entry for publisher", msgP, correlationID)) return false } if corEntry.received { // return false to return the message - publisher.logger.Debug(fmt.Sprintf("Received reply message[%p] with correlationID[%s] that already has response", msgP, correlationID)) + publisher.logger.Debug(fmt.Sprintf("Received reply message[0x%x] with correlationID[%s] that already has response", msgP, correlationID)) return false } corEntry.received = true From 99fa59a7d55b14f697458f1b4af0b172742a5359 Mon Sep 17 00:00:00 2001 From: Trent Daniel Date: Fri, 13 Dec 2024 14:54:22 -0500 Subject: [PATCH 2/4] EBP-383: Fixed a typo preventing compilation. --- internal/ccsmp/ccsmp_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/ccsmp/ccsmp_helper.c b/internal/ccsmp/ccsmp_helper.c index 919cc55..78e737e 100644 --- a/internal/ccsmp/ccsmp_helper.c +++ b/internal/ccsmp/ccsmp_helper.c @@ -59,13 +59,14 @@ solClientgo_msg_isRequestReponseMsg(solClient_opaqueMsg_pt msg_p, char **correla } solClient_returnCode_t -SessionCreate( solClient_propertyAray_pt sessionPropsP, +SessionCreate( solClient_propertyArray_pt sessionPropsP, solClient_opaqueContext_pt contextP, solClient_opaqueSession_pt *opaqueSession_p) { /* allocate the session create struct */ solClient_session_createFuncInfo_t sessionCreateFuncInfo; - sessionCreateFuncInfo.rxMsgInfo.callback_p = NULL; + sessionCreateFuncInfo.rxMsgInfo.callback_p = (solClient_session_rxMsgCallbackFunc_t)defaultMessageReceiveCallback; + sessionCreateFuncInfo.rxMsgInfo.user_p = NULL; sessionCreateFuncInfo.eventInfo.callback_p = (solClient_session_eventCallbackFunc_t)eventCallback; sessionCreateFuncInfo.eventInfo.user_p = NULL; // allocate thse struct fields to NULL too @@ -80,7 +81,7 @@ SessionContextCreate( solClient_propertyArray_pt contextPropsP, solClient_opaqueContext_pt *contextP) { /* allocate the session context create struct to NULL */ - solClient_conte3xt_createFuncInfo_t contextCreateFuncInfo; + solClient_context_createFuncInfo_t contextCreateFuncInfo; contextCreateFuncInfo.regFdInfo.user_p = NULL; contextCreateFuncInfo.regFdInfo.regFdFunc_p = NULL; contextCreateFuncInfo.regFdInfo.unregFdFunc_p = NULL; From a68603ac809707f3fe814a8ad5ef146bcb8fec92 Mon Sep 17 00:00:00 2001 From: Trent Daniel Date: Fri, 13 Dec 2024 14:59:22 -0500 Subject: [PATCH 3/4] EBP-383: Fixed formatting. --- internal/ccsmp/ccsmp_core.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/ccsmp/ccsmp_core.go b/internal/ccsmp/ccsmp_core.go index 113b8ca..8d341cf 100644 --- a/internal/ccsmp/ccsmp_core.go +++ b/internal/ccsmp/ccsmp_core.go @@ -54,6 +54,7 @@ import ( // Reexport of various CCSMP types type SolClientOpaquePointerType = C.uintptr_t + const SolClientOpaquePointerInvalidValue = SolClientOpaquePointerType(0) // SolClientContextPt is assigned a value @@ -304,7 +305,7 @@ func SolClientInitialize(props []string) *SolClientErrorInfoWrapper { func SolClientContextCreate() (context *SolClientContext, err *SolClientErrorInfoWrapper) { var contextP SolClientContextPt solClientErrorInfo := handleCcsmpError(func() SolClientReturnCode { - return C.SessionContextCreate(C.SOLCLIENT_CONTEXT_PROPS_DEFAULT_WITH_CREATE_THREAD, &contextP) + return C.SessionContextCreate(C.SOLCLIENT_CONTEXT_PROPS_DEFAULT_WITH_CREATE_THREAD, &contextP) }) if solClientErrorInfo != nil { return nil, solClientErrorInfo @@ -326,9 +327,9 @@ func (context *SolClientContext) SolClientSessionCreate(properties []string) (se defer sessionPropertiesFreeFunction() solClientErrorInfo := handleCcsmpError(func() SolClientReturnCode { - return C.SessionCreate(sessionPropsP, - context.pointer, - &sessionP) + return C.SessionCreate(sessionPropsP, + context.pointer, + &sessionP) }) if solClientErrorInfo != nil { return nil, solClientErrorInfo From efe83cbdc71f8419bbd88c67b6ada1f9b0bbf52d Mon Sep 17 00:00:00 2001 From: Trent Daniel Date: Mon, 16 Dec 2024 10:46:18 -0500 Subject: [PATCH 4/4] EBP-383: Moved include of stdint.h in solClient.h so that it is only included when compiling for the Go API. --- internal/ccsmp/lib/include/solclient/solClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ccsmp/lib/include/solclient/solClient.h b/internal/ccsmp/lib/include/solclient/solClient.h index f8692a1..859b7ce 100644 --- a/internal/ccsmp/lib/include/solclient/solClient.h +++ b/internal/ccsmp/lib/include/solclient/solClient.h @@ -18,7 +18,6 @@ #include #include #include -#include #endif #if defined(__cplusplus) @@ -570,6 +569,7 @@ typedef char ** solClient_propertyArray_pt; /**< pointer to an array of s * APIs that operate on a Context. */ #if defined(SOLCLIENT_PSPLUS_GO) +#include typedef uintptr_t solClient_opaqueContext_pt; /**< An opaque pointer to a processing Context. */ typedef uintptr_t solClient_opaqueSession_pt; /**< An opaque pointer to a Session. */ typedef uintptr_t solClient_opaqueFlow_pt; /**< An opaque pointer to a Flow. */