Skip to content

Commit

Permalink
update poll for amigaos
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf3s committed Dec 24, 2023
1 parent 0f63e7d commit 69c4866
Showing 1 changed file with 40 additions and 49 deletions.
89 changes: 40 additions & 49 deletions lib/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct MinList __filelist = { (struct MinNode *) &__filelist.mlh_Tail, NULL, (st
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <proto/exec.h>

#endif

Expand Down Expand Up @@ -155,11 +156,17 @@ int smb2_getaddrinfo(const char *node, const char*service,
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
struct hostent *host;
int i, ip[4];
#endif

#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
sin = calloc(1, sizeof(struct sockaddr_in));
#else
sin = malloc(sizeof(struct sockaddr_in));
#endif
sin->sin_len = sizeof(struct sockaddr_in);
sin->sin_family=AF_INET;

#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
/* Some error checking would be nice */
if (sscanf(node, "%d.%d.%d.%d", ip, ip+1, ip+2, ip+3) == 4) {
for (i = 0; i < 4; i++) {
Expand All @@ -183,10 +190,6 @@ int smb2_getaddrinfo(const char *node, const char*service,

*res = calloc(1, sizeof(struct addrinfo));
#else
sin = malloc(sizeof(struct sockaddr_in));
sin->sin_len = sizeof(struct sockaddr_in);
sin->sin_family=AF_INET;

/* Some error checking would be nice */
sin->sin_addr.s_addr = inet_addr(node);

Expand Down Expand Up @@ -311,18 +314,17 @@ ssize_t readv (int fd, const struct iovec *vector, int count)
#endif

#ifdef NEED_POLL
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
#include <proto/exec.h>
int poll(struct pollfd *fds, unsigned int nfds, int timo)
{
struct timeval timeout, *toptr = 0;
struct timeval timeout, *toptr;
fd_set ifds, ofds, efds, *ip, *op;
unsigned int i, maxfd = 0;
int rc;

FD_ZERO(&ifds);
FD_ZERO(&ofds);
FD_ZERO(&efds);
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
op = ip = 0;
for (i = 0; i < nfds; ++i) {
int fd = fds[i].fd;
Expand All @@ -341,49 +343,8 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo)
if (fd > maxfd) {
maxfd = fd;
}
}

if(timo >= 0) {
toptr = &timeout;
timeout.tv_sec = (unsigned)timo / 1000;
timeout.tv_usec = ((unsigned)timo % 1000) * 1000;
}

rc = select(maxfd + 1, ip, op, &efds, toptr);
if(rc <= 0)
return rc;

rc = 0;
for (i = 0; i < nfds; ++i) {
int fd = fds[i].fd;
short events = fds[i].events;
short revents = 0;
if (fd < 0)
continue;
if(events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
revents |= POLLIN;
if(events & POLLOUT && FD_ISSET(fd, &ofds))
revents |= POLLOUT;
if(FD_ISSET(fd, &efds))
revents |= POLLHUP;
if (revents) {
fds[i].revents = revents;
rc++;
}
}
return rc;
}
#else
int poll(struct pollfd *fds, unsigned int nfds, int timo)
{
struct timeval timeout, *toptr;
fd_set ifds, ofds, efds, *ip, *op;
unsigned int i, maxfd = 0;
int rc;

FD_ZERO(&ifds);
FD_ZERO(&ofds);
FD_ZERO(&efds);
for (i = 0, op = ip = 0; i < nfds; ++i) {
fds[i].revents = 0;
if(fds[i].events & (POLLIN|POLLPRI)) {
Expand All @@ -399,7 +360,16 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo)
maxfd = fds[i].fd;
}
}
#endif

#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
if(timo >= 0) {
toptr = &timeout;
timeout.tv_sec = (unsigned)timo / 1000;
timeout.tv_usec = ((unsigned)timo % 1000) * 1000;
}

#else
if(timo < 0) {
toptr = NULL;
} else {
Expand All @@ -416,13 +386,34 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo)
timeout.tv_sec = timo / 1000;
timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
#endif
#endif
}

rc = select(maxfd + 1, ip, op, &efds, toptr);

if(rc <= 0)
return rc;

#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
rc = 0;
for (i = 0; i < nfds; ++i) {
int fd = fds[i].fd;
short events = fds[i].events;
short revents = 0;
if (fd < 0)
continue;
if(events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
revents |= POLLIN;
if(events & POLLOUT && FD_ISSET(fd, &ofds))
revents |= POLLOUT;
if(FD_ISSET(fd, &efds))
revents |= POLLHUP;
if (revents) {
fds[i].revents = revents;
rc++;
}
}
#else
if(rc > 0) {
for (i = 0; i < nfds; ++i) {
int fd = fds[i].fd;
Expand All @@ -434,10 +425,10 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo)
fds[i].revents |= POLLHUP;
}
}
#endif
return rc;
}
#endif
#endif

#ifdef NEED_STRDUP
char *strdup(const char *s)
Expand Down

0 comments on commit 69c4866

Please sign in to comment.