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);
}