コード例 #1
0
/*
 * Simulate a blocking sendmsg on the non-blocking socket.
 * It's non blocking because it was set that way for recvmsg.
 */
int
rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags)
{
    fd_set *sfds = (fd_set *) 0;
    while (sendmsg(socket, msg_p, flags) == -1) {
	int err;
	rx_stats.sendSelects++;

	if (!sfds) {
	    if (!(sfds = IOMGR_AllocFDSet())) {
		(osi_Msg "rx failed to alloc fd_set: ");
		perror("rx_sendmsg");
		return -1;
	    }
	    FD_SET(socket, sfds);
	}
#if defined(HAVE_LINUX_ERRQUEUE_H) && defined(ADAPT_PMTU)
	while((rxi_HandleSocketError(socket)) > 0)
	  ;
#endif
#ifdef AFS_NT40_ENV
	if (WSAGetLastError())
#elif defined(AFS_LINUX22_ENV)
	/* linux unfortunately returns ECONNREFUSED if the target port
	 * is no longer in use */
	/* and EAGAIN if a UDP checksum is incorrect */
	if (errno != EWOULDBLOCK && errno != ENOBUFS && errno != ECONNREFUSED
	    && errno != EAGAIN)
#else
	if (errno != EWOULDBLOCK && errno != ENOBUFS)
#endif
	{
	    (osi_Msg "rx failed to send packet: ");
	    perror("rx_sendmsg");
#ifndef AFS_NT40_ENV
            if (errno > 0)
              return -errno;
#else
            if (WSAGetLastError() > 0)
              return -WSAGetLastError();
#endif
	    return -1;
	}
	while ((err = select(socket + 1, 0, sfds, 0, 0)) != 1) {
	    if (err >= 0 || errno != EINTR)
		osi_Panic("rxi_sendmsg: select error %d.%d", err, errno);
	}
    }
    if (sfds)
	IOMGR_FreeFDSet(sfds);
    return 0;
}
コード例 #2
0
ファイル: selserver.c プロジェクト: maxendpoint/openafs_cvs
void
handleWrite(clientHandle_t * ch, selcmd_t * sc)
{
    int i;
    fd_set *rfds, *wfds, *efds;
    char *buf;
    int code;
    int scode;
    char c;
    int nbytes;

    rfds = IOMGR_AllocFDSet();
    wfds = IOMGR_AllocFDSet();
    efds = IOMGR_AllocFDSet();
    assert(rfds && wfds && efds);

    if (sc->sc_delay > 0) {
	IOMGR_Sleep(sc->sc_delay);
    }

    Log("(handleWrite 0x%x) waking after %d second sleep.\n", ch->ch_pid,
	sc->sc_delay);

    if (sc->sc_flags & SC_WAIT_OOB)
	sendOOB(ch->ch_fd);

    buf = (char *)malloc(sc->sc_info);
    assert(buf);
    i = 0;

    while (1) {
	FD_ZERO(rfds);
	FD_SET(ch->ch_fd, rfds);
	FD_ZERO(efds);
	FD_SET(ch->ch_fd, efds);
	FD_ZERO(wfds);
	scode =
	    IOMGR_Select(ch->ch_fd + 1, rfds, wfds, efds,
			 (struct timeval *)0);
	assert(scode > 0);

	if (FD_ISSET(ch->ch_fd, rfds)) {

	    assert(i < sc->sc_info);

	    code = read(ch->ch_fd, &buf[i], 1);
	    i++;
	    write_I++;
	    if (code != 1) {
		Log("code =%d\n", code);
		assert(code == 1);
	    }

	    /* Test for valid fds */
	    assertNullFDSet(ch->ch_fd, rfds);
	    assertNullFDSet(-1, wfds);
	    assertNullFDSet(-1, efds);
	    if (c == END_DATA || i >= sc->sc_info) {
		break;
	    }
	}
    }
    Log("Read %d bytes of data.\n", sc->sc_info);
    nbytes = write(ch->ch_fd, buf, sc->sc_info);
    assert(nbytes == sc->sc_info);
    Log("Wrote data back to client.\n");
    IOMGR_FreeFDSet(rfds);
    IOMGR_FreeFDSet(wfds);
    IOMGR_FreeFDSet(efds);
}