sconsole

bare bones linux serial console tool
git clone http://frotz.net/git/sconsole.git
Log | Files | Refs

apple.c (1305B)


      1 // Copyright 2005-2022, Brian Swetland <swetland@frotz.net>
      2 // Licensed under the Apache License, Version 2.0
      3 
      4 #include <IOKit/serial/ioss.h>
      5 #define B4000000 4000000
      6 #define B3500000 3500000
      7 #define B3000000 3000000
      8 #define B2500000 2500000
      9 #define B2000000 2000000
     10 #define B1500000 1500000
     11 #define B1152000 1152000
     12 #define B1000000 1000000
     13 #define B921600 921600
     14 
     15 /* Darwin's poll is broken.  Implement a replacement using select */
     16 int select_poll(struct pollfd *fds, int nfds, int timeout)
     17 {
     18 	fd_set rfds;
     19 	fd_set wfds;
     20 	fd_set efds;
     21 	int max_fd = 0;
     22 	int retval;
     23 	struct timeval tv;
     24 	int i;
     25 
     26 	FD_ZERO(&rfds);
     27 	FD_ZERO(&wfds);
     28 	FD_ZERO(&efds);
     29 
     30 	for (i = 0; i < nfds; i++) {
     31 		if (fds[i].events == POLLIN)
     32 			FD_SET(fds[i].fd, &rfds);
     33 		if (fds[i].events == POLLOUT)
     34 			FD_SET(fds[i].fd, &wfds);
     35 		FD_SET(fds[i].fd, &efds);
     36 
     37 		if (fds[i].fd > max_fd)
     38 			max_fd = fds[i].fd;
     39 
     40 		fds[i].revents = 0;
     41 	}
     42 
     43 	retval = select(max_fd + 1, &rfds, &wfds, &efds, NULL);
     44 
     45 	if (errno == EAGAIN) {
     46 		return 0;
     47 	}
     48 
     49 	if (retval < 0) {
     50 		return -1;
     51 	}
     52 
     53 	for (i = 0; i < nfds; i++ ) {
     54 		if (FD_ISSET(fds[i].fd, &rfds))
     55 			fds[i].revents |= POLLIN;
     56 		if (FD_ISSET(fds[i].fd, &wfds))
     57 			fds[i].revents |= POLLOUT;
     58 		if (FD_ISSET(fds[i].fd, &efds))
     59 			fds[i].revents |= POLLERR;
     60 	}
     61 
     62 	return 1;
     63 }
     64 
     65 #define poll select_poll
     66