Skip to content

Commit

Permalink
Fixed poll.h *readerCount++ error reported by TankorSmash
Browse files Browse the repository at this point in the history
  • Loading branch information
robinrowe committed Oct 29, 2018
1 parent 198b481 commit 70900ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
16 changes: 2 additions & 14 deletions test/mman/mman_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@
#include <unistd.h>
#include <string.h>
#include <assert.h>

#ifndef _WIN32
#define shm_close close
#define shm_flush(fd)

int shm_size(int fd)
{ struct stat sb;
fstat(fd, &sb);
off_t length = sb.st_size;
return int(length);
}
#endif
#include <more/shm_more.h>

int main(int argc, char **argv)
{ int oflags=O_RDWR;
int i;
char *name = "/mmanjunk";
int fd = shm_open(name, oflags, 0644 );
fprintf(stderr,"Shared Mem Descriptor: fd=%d\n", fd);
printf("Shared Mem Descriptor: fd=%d\n", fd);
assert (fd>0);
size_t length = shm_size(fd);
char* p = (char *) mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
Expand Down
6 changes: 1 addition & 5 deletions test/mman/mman_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#include <unistd.h>
#include <string.h>
#include <assert.h>

#ifndef _WIN32
#define shm_close close
#define shm_ftruncate ftruncate
#endif
#include <more/shm_more.h>

int main(int argc, char **argv)
{ int oflags=O_RDWR;
Expand Down
24 changes: 24 additions & 0 deletions unistd/more/shm_more.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// unistd/more/shm_more.h
// 2018/10/28 Robin.Rowe@CinePaint.org

#ifndef shm_more_h
#define shm_more_h

#ifndef _WIN32

#include <sys/stat.h>
#include <fcntl.h>

#define shm_close close
#define shm_ftruncate ftruncate
#define shm_flush(fd)

int shm_size(int fd)
{ struct stat sb;
fstat(fd, &sb);
off_t length = sb.st_size;
return int(length);
}
#endif

#endif
8 changes: 4 additions & 4 deletions unistd/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ int poll(struct pollfd *fds, nfds_t nfds, int mille_timeout)
if(!fd)
{ return -1;
}
u_int* readerCount=&fd[0].fd_count;
u_int* const readerCount=&fd[0].fd_count;
*readerCount=0;
SOCKET* fdReader=fd[0].fd_array;
int writer=nfds;
u_int* writerCount=&fd[nfds].fd_count;
u_int* const writerCount=&fd[nfds].fd_count;
*writerCount=0;
SOCKET* fdWriter=fd[nfds].fd_array;
for(int i=0;i<nfds;i++)
{ if(fds[i].events & POLLIN)
{ fdReader[*readerCount]=fds[i].fd;
*readerCount++;
(*readerCount)++;
}
if(fds[i].events & POLLOUT)
{ fdWriter[*writerCount]=fds[i].fd;
*writerCount++;
(*writerCount)++;
} }
fd_set fdExcept;
fdExcept.fd_count=0;
Expand Down

0 comments on commit 70900ef

Please sign in to comment.