Intel Forum,
I am attempting to pass data between two processes written in Fortran.
Process A is the main process which establishes a socket connection with a Java-based process.
Process B is created from Process A using the CreateProcess function.
I am attempting to duplicate the socket within Process B from the socket established in Process A.
[ Process A Snippet ]
---------------------
TYPE(T_STARTUPINFO) :: sinfo
TYPE(T_PROCESS_INFORMATION) :: pinfo
TYPE(T_WSAPROTOCOL_INFOA) :: protInfo
c
. . . . . . . . .
c
c ------------------
c - Create Process B.
c ------------------
c
c
cmdLine = "C:\\Base_Dir\\Process_B.exe"
c
cmdLine = cmdLine(1:len_trim(cmdLine)) // char(0)
c
returnVal = CreateProcess(NULL,
& cmdLine,
& NULL_SECURITY_ATTRIBUTES,
& NULL_SECURITY_ATTRIBUTES,
& TRUE,
& CREATE_PRESERVE_CODE_AUTHZ_LEVEL,
& NULL,
& NULL,
& sinfo,
& pinfo)
c
. . . . . . . . .
c
c - Create a new socket descriptor for a shared socket.
c
status = WSADuplicateSocket(sockid,
& pinfo.dwProcessId,
& protInfo)
[ Process B Snippet ]
---------------------
TYPE(T_WSADATA) wsaInfo
c
. . . . . . . . .
c
consock = WSASocket(AF_INET,
& SOCK_STREAM,
& IPPROTO_TCP,
& protInfo,
& 0,
& 0)
c
ierror = WSAGetLastError()
Question:
--------
The MSDN website states the following in reference to SHARED SOCKETS ...
"Shared Sockets"
The WSADuplicateSocket function is introduced to enable socket sharing across processes.
A source process calls WSADuplicateSocket to obtain a special WSAPROTOCOL_INFO structure for a
target process identifier. It uses some interprocess communications (IPC) mechanism to pass the
contents of this structure to a target process. The target process then uses the WSAPROTOCOL_INFO
structure in a call to WSPSocket. The socket descriptor returned by this function will be an
additional socket descriptor to an underlying socket which thus becomes shared.
A typical example of sharing sockets is to use one process for creating sockets and establishing connections.
This process then hands off sockets to other processes that are responsible for information exchange.
As I understand, I need to pass the contents of the "protInfo" structure (previously cast as T_WSAPROTOCOL_INFO)
to Process B via some "interprocess communications (IPC) mechanism".
What would that (IPC) mechanism be? (Most efficient)
Note:
I have even thought of putting the "TYPE(T_WSAPROTOCOL_INFOA) :: protInfo" declaration with a DLL library to be shared
between the two processes, but I understand at least one member of the structure needs to be initialized to be seen across
both processes, which I cannot seem to figure out.
Has someone come across the same dilemma, and is there a working example which I may reference?
Thank you in advance.