minix/lib/libc/asyn/asyn_write.c

50 lines
1.1 KiB
C
Raw Normal View History

This patch switches the MINIX3 ethernet driver stack from a port-based model to an instance-based model. Each ethernet driver instance is now responsible for exactly one network interface card. The port field in /etc/inet.conf now acts as an instance field instead. This patch also updates the data link protocol. This update: - eliminates the concept of ports entirely; - eliminates DL_GETNAME entirely; - standardizes on using m_source for IPC and DL_ENDPT for safecopies; - removes error codes from TASK/STAT replies, as they were unused; - removes a number of other old or unused fields; - names and renames a few other fields. All ethernet drivers have been changed to: - conform to the new protocol, and exactly that; - take on an instance number based on a given "instance" argument; - skip that number of PCI devices in probe iterations; - use config tables and environment variables based on that number; - no longer be limited to a predefined maximum of cards in any way; - get rid of any leftover non-safecopy support and other ancient junk; - have a correct banner protocol figure, or none at all. Other changes: * Inet.conf is now taken to be line-based, and supports #-comments. No existing installations are expected to be affected by this. * A new, select-based asynchio library replaces the old one. Kindly contributed by Kees J. Bot. * Inet now supports use of select() on IP devices. Combined, the last two changes together speed up dhcpd considerably in the presence of multiple interfaces. * A small bug has been fixed in nonamed.
2010-05-18 00:22:53 +02:00
/* asyn_write() Author: Kees J. Bot
* 7 Jul 1997
*/
#include "asyn.h"
#include <signal.h>
ssize_t asyn_write(asynchio_t *asyn, int fd, const void *buf, size_t len)
/* Nonblocking write(). (See asyn_read()). */
{
asynfd_t *afd;
asyn->asyn_more++;
if ((unsigned) fd >= FD_SETSIZE) { errno= EBADF; return -1; }
afd= &asyn->asyn_afd[fd];
if (!afd->afd_seen) {
if ((afd->afd_flags= fcntl(fd, F_GETFL)) < 0) return -1;
afd->afd_seen= 1;
}
if (afd->afd_state[SEL_WRITE] == PENDING) {
sigset_t mask;
ssize_t result;
int err;
sigemptyset(&mask);
if (sigprocmask(SIG_SETMASK, &mask, &mask) < 0) return -1;
(void) fcntl(fd, F_SETFL, afd->afd_flags | O_NONBLOCK);
result= write(fd, buf, len);
err= errno;
(void) fcntl(fd, F_SETFL, afd->afd_flags);
(void) sigprocmask(SIG_SETMASK, &mask, nil);
errno= err;
if (result != -1 || errno != EAGAIN) {
afd->afd_state[SEL_WRITE]= IDLE;
return result;
}
}
afd->afd_state[SEL_WRITE]= WAITING;
FD_SET(fd, &asyn->asyn_fdset[SEL_WRITE]);
errno= EAGAIN;
asyn->asyn_more--;
return -1;
}