Say I want to have a server that can accept socket connection and also can monitor devices which are plugged in the server.
There will be two things the server can do.
1. Accept/Monitor Client connections via TCP/IP(recv and send from them);
2. Monitor Devices(recv and send from the devices);
From number 1 i plan to use linux sockets to accept client connections.
From number 2 i plan to use libudev.h library to monitor devices. which have a tutorial on signal11..
I have already code linux sockets and libudev.h.. but they’re separate user space app. I need to merge them as one.. How am i supposed to do this?.
Or any suggestions how can i do this? THanks.
So you need to multiplex your I/O?
If that’s all you’re asking then you have a selection of options. The traditional UNIX way would be to use select or poll. – http://www.linux-mag.com/id/331/
Or you could go for spawning threads for each of the connections that need I/O done on them. This is naturally the easiest option, but is fraught with risk in terms of maintaining data integrity between the two threads, locking and race conditions make a solid implementation trickier (I think) than poll.
You could of course still keep them as separate processes and then use some method of IPC (Shared memory, message queues etc.) to a third process to unify the functionality of the two. This is perhaps a little heavier than the threaded option but with better separation between the two processes, making it more resilient at the cost of (potentially) more work.
Can you clarify your question a little more?!