Commit fec1aa82df00ce86f9cf96ae0902497129b6b40f

Authored by Wiebe Cazemier
1 parent c036ae83

Fixed error checks

Showing 1 changed file with 7 additions and 6 deletions
main.cpp
@@ -74,19 +74,20 @@ int main() @@ -74,19 +74,20 @@ int main()
74 { 74 {
75 int listen_fd = socket(AF_INET, SOCK_STREAM, 0); 75 int listen_fd = socket(AF_INET, SOCK_STREAM, 0);
76 76
77 - int optval = 1;  
78 - check<std::runtime_error>(setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &optval, sizeof(optval)) < 0); 77 + // Not needed for now. Maybe I will make multiple accept threads later, with SO_REUSEPORT.
  78 + //int optval = 1;
  79 + //check<std::runtime_error>(setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &optval, sizeof(optval)));
79 80
80 int flags = fcntl(listen_fd, F_GETFL); 81 int flags = fcntl(listen_fd, F_GETFL);
81 - check<std::runtime_error>(fcntl(listen_fd, F_SETFL, flags | O_NONBLOCK ) < 0); 82 + check<std::runtime_error>(fcntl(listen_fd, F_SETFL, flags | O_NONBLOCK ));
82 83
83 struct sockaddr_in in_addr; 84 struct sockaddr_in in_addr;
84 in_addr.sin_family = AF_INET; 85 in_addr.sin_family = AF_INET;
85 in_addr.sin_addr.s_addr = INADDR_ANY; 86 in_addr.sin_addr.s_addr = INADDR_ANY;
86 in_addr.sin_port = htons(1883); 87 in_addr.sin_port = htons(1883);
87 88
88 - check<std::runtime_error>(bind(listen_fd, (struct sockaddr *)(&in_addr), sizeof(struct sockaddr_in)) < 0);  
89 - check<std::runtime_error>(listen(listen_fd, 1024) < 0); 89 + check<std::runtime_error>(bind(listen_fd, (struct sockaddr *)(&in_addr), sizeof(struct sockaddr_in)));
  90 + check<std::runtime_error>(listen(listen_fd, 1024));
90 91
91 int epoll_fd_accept = check<std::runtime_error>(epoll_create(999)); 92 int epoll_fd_accept = check<std::runtime_error>(epoll_create(999));
92 93
@@ -97,7 +98,7 @@ int main() @@ -97,7 +98,7 @@ int main()
97 98
98 ev.data.fd = listen_fd; 99 ev.data.fd = listen_fd;
99 ev.events = EPOLLIN; 100 ev.events = EPOLLIN;
100 - check<std::runtime_error>(epoll_ctl(epoll_fd_accept, EPOLL_CTL_ADD, listen_fd, &ev) < 0); 101 + check<std::runtime_error>(epoll_ctl(epoll_fd_accept, EPOLL_CTL_ADD, listen_fd, &ev));
101 102
102 std::vector<std::shared_ptr<ThreadData>> threads; 103 std::vector<std::shared_ptr<ThreadData>> threads;
103 104