Skip to content

Commit

Permalink
windows fixes (Gregory Alexander)
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1102 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
bellard committed Oct 7, 2004
1 parent 890fa6b commit 02d2c54
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
6 changes: 3 additions & 3 deletions slirp/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ writen(fd, bptr, n)
int total;

/* This should succeed most of the time */
ret = write(fd, bptr, n);
ret = send(fd, bptr, n,0);
if (ret == n || ret <= 0)
return ret;

/* Didn't write everything, go into the loop */
total = ret;
while (n > total) {
ret = write(fd, bptr+total, n-total);
ret = send(fd, bptr+total, n-total,0);
if (ret <= 0)
return ret;
total += ret;
Expand All @@ -111,7 +111,7 @@ if_input(ttyp)
DEBUG_CALL("if_input");
DEBUG_ARG("ttyp = %lx", (long)ttyp);

if_n = read(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE);
if_n = recv(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE,0);

DEBUG_MISC((dfd, " read %d bytes\n", if_n));

Expand Down
15 changes: 12 additions & 3 deletions slirp/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
/* Connected */
so->so_state &= ~SS_ISFCONNECTING;

ret = write(so->s, &ret, 0);
ret = send(so->s, &ret, 0, 0);
if (ret < 0) {
/* XXXXX Must fix, zero bytes is a NOP */
if (errno == EAGAIN || errno == EWOULDBLOCK ||
Expand Down Expand Up @@ -447,7 +447,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
*/
#ifdef PROBE_CONN
if (so->so_state & SS_ISFCONNECTING) {
ret = read(so->s, (char *)&ret, 0);
ret = recv(so->s, (char *)&ret, 0,0);

if (ret < 0) {
/* XXX */
Expand All @@ -460,7 +460,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)

/* tcp_input will take care of it */
} else {
ret = write(so->s, &ret, 0);
ret = send(so->s, &ret, 0,0);
if (ret < 0) {
/* XXX */
if (errno == EAGAIN || errno == EWOULDBLOCK ||
Expand Down Expand Up @@ -496,6 +496,15 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
*/
if (if_queued && link_up)
if_start();

/* clear global file descriptor sets.
* these reside on the stack in vl.c
* so they're unusable if we're not in
* slirp_select_fill or slirp_select_poll.
*/
global_readfds = NULL;
global_writefds = NULL;
global_xfds = NULL;
}

#define ETH_ALEN 6
Expand Down
4 changes: 4 additions & 0 deletions slirp/slirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,8 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
#define max(x,y) ((x) > (y) ? (x) : (y))
#endif

#ifdef _WIN32
#define errno (WSAGetLastError())
#endif

#endif
26 changes: 18 additions & 8 deletions slirp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ soread(so)
nn = readv(so->s, (struct iovec *)iov, n);
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#else
nn = read(so->s, iov[0].iov_base, iov[0].iov_len);
nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
#endif
if (nn <= 0) {
if (nn < 0 && (errno == EINTR || errno == EAGAIN))
Expand All @@ -176,7 +176,7 @@ soread(so)
* A return of -1 wont (shouldn't) happen, since it didn't happen above
*/
if (n == 2 && nn == iov[0].iov_len)
nn += read(so->s, iov[1].iov_base, iov[1].iov_len);
nn += recv(so->s, iov[1].iov_base, iov[1].iov_len,0);

DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#endif
Expand Down Expand Up @@ -333,7 +333,7 @@ sowrite(so)

DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
#else
nn = write(so->s, iov[0].iov_base, iov[0].iov_len);
nn = send(so->s, iov[0].iov_base, iov[0].iov_len,0);
#endif
/* This should never happen, but people tell me it does *shrug* */
if (nn < 0 && (errno == EAGAIN || errno == EINTR))
Expand All @@ -349,7 +349,7 @@ sowrite(so)

#ifndef HAVE_READV
if (n == 2 && nn == iov[0].iov_len)
nn += write(so->s, iov[1].iov_base, iov[1].iov_len);
nn += send(so->s, iov[1].iov_base, iov[1].iov_len,0);
DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
#endif

Expand Down Expand Up @@ -572,7 +572,11 @@ solisten(port, laddr, lport, flags)
close(s);
sofree(so);
/* Restore the real errno */
#ifdef _WIN32
WSASetLastError(tmperrno);
#else
errno = tmperrno;
#endif
return NULL;
}
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
Expand Down Expand Up @@ -643,7 +647,9 @@ sofcantrcvmore(so)
{
if ((so->so_state & SS_NOFDREF) == 0) {
shutdown(so->s,0);
FD_CLR(so->s, global_writefds);
if(global_writefds) {
FD_CLR(so->s,global_writefds);
}
}
so->so_state &= ~(SS_ISFCONNECTING);
if (so->so_state & SS_FCANTSENDMORE)
Expand All @@ -657,9 +663,13 @@ sofcantsendmore(so)
struct socket *so;
{
if ((so->so_state & SS_NOFDREF) == 0) {
shutdown(so->s,1); /* send FIN to fhost */
FD_CLR(so->s, global_readfds);
FD_CLR(so->s, global_xfds);
shutdown(so->s,1); /* send FIN to fhost */
if (global_readfds) {
FD_CLR(so->s,global_readfds);
}
if (global_xfds) {
FD_CLR(so->s,global_xfds);
}
}
so->so_state &= ~(SS_ISFCONNECTING);
if (so->so_state & SS_FCANTRCVMORE)
Expand Down
2 changes: 1 addition & 1 deletion slirp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ tcp_input(m, iphlen, inso)
goto cont_input;
}

if(tcp_fconnect(so) == -1 && errno != EINPROGRESS) {
if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
u_char code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n",
errno,strerror(errno)));
Expand Down
4 changes: 4 additions & 0 deletions slirp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ udp_attach(so)
int lasterrno=errno;
closesocket(so->s);
so->s=-1;
#ifdef _WIN32
WSASetLastError(lasterrno);
#else
errno=lasterrno;
#endif
} else {
/* success, insert in queue */
so->so_expire = curtime + SO_EXPIRE;
Expand Down

0 comments on commit 02d2c54

Please sign in to comment.