I am trying to port a legacy Delphi code in windows to Linux. But I am facing difficulty in finding out the equivalent of few windows functions in Linux. Currently I have a block of code that does socket operations using winsock, the outline of the code is as below(as I cant post the actual entire code due to security reason) . So any suggestion on how to achieve the same functionality in Linux(not necessarily for Delphi, but it can be in C/C++) would be of great help.
My understanding about the below code is that the thread creates a window and wait for the message WM_USER and later when the program creates a socket, program registers the socket to send the WM_USER message once it has any event among FD_READ or FD_WRITE or FD_ACCEPT or FD_CONNECT or FD_CLOSE. Once the socket has any of the event mentioned in the list, it send a WM_USER message and the window handler process this message. So my question here is how can I implement the similar functionality in Linux when I port the program to Linux?
int main()
{
...
1. A thread is created and which executes the function thread_Function() shown below
....
....
2. Now the program creates a TCP socket(TheSocket), sets few socket options and does the binding and invokes the WSAAsyncSelect() functionas follows on the socket
if WSAAsyncSelect(TheSocket, WindowHandle, WM_USER,
FD_READ or FD_WRITE or FD_ACCEPT or FD_CONNECT or FD_CLOSE)
}
void thread_Function()
{
WindowHandle := CreateWindow(
name, name, // class name, window name
0, 0, 0, 0, 0, // window style, x, y, width, hight
0, 0, // handle to parent and menu or child-window identifier
HInstance,// handle to application instance
nil); // pointer to window-creation data
if WindowHandle = 0 then
Print('Can''t create window handle: '+SysErrorMessage(GetLastError))
else begin
while GetMessage(Msg, 0, 0, 0) do begin
if Msg.message = WM_USER then begin
HandleSocketMessage()
end
end
end
}