0

I've asked this question but in SCTP environment, I didn't get any answer so I'll ask here with tcp as I can use the same design in both protocol(almost)

Let's say I have multiple tcp connections opened by the main program, and I have mutiple-threads, 4 for example.

The application requires me to use all 4 connection in a round-robin fashion, but sometimes I need to send over one specific TCP connection, you can say it's a tcp based routing, so what I was thinking about is to create 4 tcp connection in the main program, with the following file descriptors,

fd1
fd2
fd3
fd4

and share these file descriptors with 4 threads, so each thread can send to any of these fds of course with locks, is that a good idea? if not what do you suggest?

The pseudo code is below is gonna send to tcp_fd[0] if routing==something and send to any of the fds if routing is not specified. the environment is linux and C.

main()
{

tcp_fd[0] = create_connections(1);
tcp_fd[1] = create_connections(3);
tcp_fd[2] = create_connections(3);
tcp_fd[3] = create_connections(3);

create_threads(function_send, tcp_fd)

}


function_send(tcp_fd[])
{
get_data_from_fifo();

if(routing==something)
send_tcp_msg(tcp_fd[0],round_robin_disabled);
else
send_tcp_msg(to any tcp_fd,round_robin_enabled);


}
user1832809
  • 71
  • 11
  • it seems `round_robin_enabled/_disabled` should be the other way around in the pseudo-code. The question is not clear. You could do the same using a single thread or you could dedicate a separate thread for each connection. Do you have a specific problem? – jfs Dec 13 '12 at 05:29
  • A little more description of what you want to do might be nice, but from what I see here that could work. What kind of locking mechanism would you plan to use? – darkpbj Dec 13 '12 at 05:29
  • @J.F, yes that's right it's the other way around, as I mentioned, this is an SCTP scenario and not TCP, I put the question in TCP so anyone with TCP knowledge can answer it. – user1832809 Dec 13 '12 at 07:34
  • @darkpbj, I've mentioned what I wanna do, I wanna send to one specific tcp connection when some rule apply and to the rest in the default situation. – user1832809 Dec 13 '12 at 07:37
  • this was my first question http://stackoverflow.com/questions/13832273/sctp-association – user1832809 Dec 13 '12 at 07:38

0 Answers0