I'm trying to create asynchronous high performance UDP client. I'm implementing UDP tracker protocol.
Lets say I have 1000 torrent hashes. I need to make 1000/74 ~= 14 UDP requests, assuming that UDP tracker don't have any limits. UDP Tracker protocol supports up to 74 hashes per request via UDP protocol, so i need to create 14 UDP sockets.
I need to use epoll, not poll, select, libevent, libev or libuv.
Every epoll UDP example I find is for server, not client.
I'm having troubles with understanding application logic.
First, i need to create 14 sockets:
#define MAX_CLIENTS 14
int fd[MAX_CLIENTS];
for (i = 0; i < MAX_CLIENTS; i++) {
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(EXIT_FAILURE);
}
setnonblock(fd[i]);
}
Then
int efd = epoll_create(MAX_EVENTS);
Now I need to send data via sendto for each of this socket, and receive results via epoll. How can I do that ?
I don't need someone to write code for me, I just want to understand epoll logic better.
This is highly theoretical question so I can understand epoll better. Please don't refer me to pthreads or libevent, this is not my question. Also, I'm not interested in HTTP implementation of Torrent Tracker protocol.
Similar threads: