0

I have a program that needs to:

  • Handle 20 connections. My program will act as client in every connection, each client connecting to a different server.
  • Once connected my client should send a request to the server every second and wait for a response. If no request is sent within 9 seconds, the server will time out the client.
  • It is unacceptable for one connection to cause problems for the rest of the connections.
  • I do not have access to threads and I do not have access to non-blocking sockets. I have a single-threaded program with blocking sockets.
  • Edit: The reason I cannot use threads and non blocking sockets is that I am on a non-standard system. I have a single RTOS(Real-Time Operating System) task available.

To solve this, use of select is necessary but I am not sure if it is sufficient.

Initially I connect to all clients. But select can only be used to see if a read or write will block or not, not if a connect will. So when I have connected to say 2 clients and they are all waiting to be served, what if the 3rd does not work, the connection will block causing the first 2 connections to time out as well.

Can this be solved?

Soft Ware
  • 141
  • 3
  • 11
  • are you sure you don't have threads available. The very concept of an OS involves the existence of threads and processes. So no matter wha RTOS you are using it should have these – Pandrei Feb 12 '15 at 15:58

2 Answers2

0

I think the connection-issue can be solved by setting a timeout for the connect-operation, so that it will fail fast enough. Of course that will limit you if the network really is working, but you have a very long (slow) path to some of the server(s). That's bad design, but your requirements are pretty harsh.

See this answer for details on connection-timeouts.

Community
  • 1
  • 1
unwind
  • 391,730
  • 64
  • 469
  • 606
0

It seems you need to isolate the connections. Well, if you cannot use threads you can always resort to good-old-processes. Spawn each client by forking your server process and use traditional IPC mechanisms if communication between them is required.

If you can neither use a multiprocess approach I'm afraid you'll have a hard time doing that.

DieMartin
  • 66
  • 1