Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing select() with poll() in socket_linux.c #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions lib60870-C/src/hal/socket/linux/socket_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "hal_socket.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <poll.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -478,10 +478,6 @@ Socket_connectAsync(Socket self, const char* address, int port)
if (!prepareAddress(address, port, &serverAddress))
return false;

fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);

activateTcpNoDelay(self);

fcntl(self->fd, F_SETFL, O_NONBLOCK);
Expand All @@ -505,15 +501,12 @@ Socket_connectAsync(Socket self, const char* address, int port)
SocketState
Socket_checkAsyncConnectState(Socket self)
{
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
struct pollfd fdSet;
fdSet.fd = self->fd;
fdSet.events = POLLOUT;
fdSet.revents = 0;

fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);

int selectVal = select(self->fd + 1, NULL, &fdSet , NULL, &timeout);
int selectVal = poll(&fdSet, 1, 0);

if (selectVal == 1) {

Expand Down Expand Up @@ -544,15 +537,12 @@ Socket_connect(Socket self, const char* address, int port)
if (Socket_connectAsync(self, address, port) == false)
return false;

struct timeval timeout;
timeout.tv_sec = self->connectTimeout / 1000;
timeout.tv_usec = (self->connectTimeout % 1000) * 1000;

fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(self->fd, &fdSet);
struct pollfd fdSet;
fdSet.fd = self->fd;
fdSet.events = POLLOUT;
fdSet.revents = 0;

if (select(self->fd + 1, NULL, &fdSet , NULL, &timeout) == 1) {
if (poll(&fdSet, 1, self->connectTimeout) == 1) {

/* Check if connection is established */

Expand Down