...
authoralex <[email protected]>
Thu, 5 May 2022 01:42:40 +0000 (18:42 -0700)
committeralex <[email protected]>
Thu, 5 May 2022 01:42:40 +0000 (18:42 -0700)
src/net/loop.c

index 0ee81bfedc787b685e47718b6857eb1f2624261a..97704362ec025b6d0dd4b302f47fd2a535fd92da 100644 (file)
@@ -13,6 +13,7 @@ void net_loop(struct net_info *info) {
 
 static void net_await_epoll_event(struct net_info *info) {
        struct epoll_event ev, events[MAX_EVENTS];
+       struct peer *peer;
        int nfds, conn_sock;
 
        nfds = epoll_wait(info->epoll_fd,events,MAX_EVENTS,-1);
@@ -34,11 +35,12 @@ static void net_await_epoll_event(struct net_info *info) {
                        ev.events = EPOLLIN | EPOLLET;
                        ev.data.fd = conn_sock;
 
-                       if(peer_init((struct peer**)ev.data.ptr)<0) {
+                       if(peer_init(&peer)<0) {
                               return;
                        }
 
-                       ((struct peer*)ev.data.ptr)->sock = conn_sock;
+                       peer->sock = conn_sock;
+                       ev.data.ptr = peer;
 
                        if(-1==epoll_ctl(info->epoll_fd,EPOLL_CTL_ADD,conn_sock,&ev)) {
                                peer_free(ev.data.ptr);