Skip to content

Commit

Permalink
stream-fd: Merge stream-fd-windows and stream-fd-unix.
Browse files Browse the repository at this point in the history
There was not much difference between the two files after moving
all of the Windows socket HANDLE polling functionality to poll-loop.c.
So merge them together.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
  • Loading branch information
shettyg committed Oct 20, 2014
1 parent f0d2e45 commit c48f691
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 286 deletions.
5 changes: 2 additions & 3 deletions lib/automake.mk
Expand Up @@ -212,6 +212,7 @@ lib_libopenvswitch_la_SOURCES = \
lib/sset.h \
lib/stp.c \
lib/stp.h \
lib/stream-fd.c \
lib/stream-fd.h \
lib/stream-provider.h \
lib/stream-ssl.h \
Expand Down Expand Up @@ -265,16 +266,14 @@ lib_libopenvswitch_la_SOURCES += \
lib/getrusage-windows.c \
lib/latch-windows.c \
lib/route-table-stub.c \
lib/strsep.c \
lib/stream-fd-windows.c
lib/strsep.c
else
lib_libopenvswitch_la_SOURCES += \
lib/daemon-unix.c \
lib/latch-unix.c \
lib/signals.c \
lib/signals.h \
lib/socket-util-unix.c \
lib/stream-fd-unix.c \
lib/stream-unix.c
endif

Expand Down
270 changes: 0 additions & 270 deletions lib/stream-fd-windows.c

This file was deleted.

55 changes: 42 additions & 13 deletions lib/stream-fd-unix.c → lib/stream-fd.c
Expand Up @@ -77,7 +77,7 @@ static void
fd_close(struct stream *stream)
{
struct stream_fd *s = stream_fd_cast(stream);
close(s->fd);
closesocket(s->fd);
free(s);
}

Expand All @@ -93,21 +93,45 @@ fd_recv(struct stream *stream, void *buffer, size_t n)
{
struct stream_fd *s = stream_fd_cast(stream);
ssize_t retval;

retval = read(s->fd, buffer, n);
return retval >= 0 ? retval : -errno;
int error;

retval = recv(s->fd, buffer, n, 0);
if (retval < 0) {
error = sock_errno();
#ifdef _WIN32
if (error == WSAEWOULDBLOCK) {
error = EAGAIN;
}
#endif
if (error != EAGAIN) {
VLOG_DBG_RL(&rl, "recv: %s", sock_strerror(error));
}
return -error;
}
return retval;
}

static ssize_t
fd_send(struct stream *stream, const void *buffer, size_t n)
{
struct stream_fd *s = stream_fd_cast(stream);
ssize_t retval;

retval = write(s->fd, buffer, n);
return (retval > 0 ? retval
: retval == 0 ? -EAGAIN
: -errno);
int error;

retval = send(s->fd, buffer, n, 0);
if (retval < 0) {
error = sock_errno();
#ifdef _WIN32
if (error == WSAEWOULDBLOCK) {
error = EAGAIN;
}
#endif
if (error != EAGAIN) {
VLOG_DBG_RL(&rl, "recv: %s", sock_strerror(error));
}
return -error;
}
return (retval > 0 ? retval : -EAGAIN);
}

static void
Expand Down Expand Up @@ -198,7 +222,7 @@ static void
pfd_close(struct pstream *pstream)
{
struct fd_pstream *ps = fd_pstream_cast(pstream);
close(ps->fd);
closesocket(ps->fd);
maybe_unlink_and_free(ps->unlink_path);
free(ps);
}
Expand All @@ -214,16 +238,21 @@ pfd_accept(struct pstream *pstream, struct stream **new_streamp)

new_fd = accept(ps->fd, (struct sockaddr *) &ss, &ss_len);
if (new_fd < 0) {
retval = errno;
retval = sock_errno();
#ifdef _WIN32
if (retval == WSAEWOULDBLOCK) {
retval = EAGAIN;
}
#endif
if (retval != EAGAIN) {
VLOG_DBG_RL(&rl, "accept: %s", ovs_strerror(retval));
VLOG_DBG_RL(&rl, "accept: %s", sock_strerror(retval));
}
return retval;
}

retval = set_nonblocking(new_fd);
if (retval) {
close(new_fd);
closesocket(new_fd);
return retval;
}

Expand Down

0 comments on commit c48f691

Please sign in to comment.