Skip to content

Commit

Permalink
Merge from HEAD:
Browse files Browse the repository at this point in the history
    * lib/libonyx/src/systemdict.c:systemdict_send() : Loop when short
      writes happen until all the data are written.

      systemdict_recv() : Loop when recv() is interrupted.

      systemdict_waitpid() : Loop when waitpid() is interrupted.
  • Loading branch information
jasone committed Mar 21, 2003
1 parent 517a5ef commit 3789b79
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 44 deletions.
7 changes: 7 additions & 0 deletions branches/ONYX_4_4/devroot/CHANGES.onyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
2003-03-20 : Jason Evans <jasone@canonware.com>

* lib/libonyx/src/systemdict.c:systemdict_send() : Loop when short
writes happen until all the data are written.

systemdict_recv() : Loop when recv() is interrupted.

systemdict_waitpid() : Loop when waitpid() is interrupted.

* bin/onyx/src/onyx.c:main() : Add a top level exception handler.

* lib/libonyx/include/libonyx/xep.h : Add xep_filename() and
Expand Down
114 changes: 70 additions & 44 deletions branches/ONYX_4_4/devroot/lib/libonyx/src/systemdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <dirent.h> /* For dirforeach operator. */
#ifdef CW_SOCKET
#include <fcntl.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
Expand Down Expand Up @@ -8002,8 +8003,11 @@ systemdict_recv(cw_nxo_t *a_thread)
}

nxo_string_lock(nxo);
nread = recv(nxo_file_fd_get(sock), nxo_string_get(nxo),
nxo_string_len_get(nxo), flags);
while ((nread = recv(nxo_file_fd_get(sock), nxo_string_get(nxo),
nxo_string_len_get(nxo), flags)) == -1 && errno == EINTR)
{
/* EINTR; try again. */
}
nxo_string_unlock(nxo);

if (nread == -1)
Expand All @@ -8028,7 +8032,6 @@ systemdict_recv(cw_nxo_t *a_thread)
}
case EBADF:
case EFAULT:
case EINTR:
case EINVAL:
default:
{
Expand Down Expand Up @@ -8796,8 +8799,11 @@ void
systemdict_send(cw_nxo_t *a_thread)
{
cw_nxo_t *ostack, *sock, *nxo;
cw_uint32_t npop;
int flags, nwrite;
cw_uint8_t *str;
cw_uint32_t npop, len;
int fd, flags;
ssize_t count, nwritten;
cw_bool_t blocking;

ostack = nxo_thread_ostack_get(a_thread);

Expand Down Expand Up @@ -8843,51 +8849,64 @@ systemdict_send(cw_nxo_t *a_thread)
return;
}

fd = nxo_file_fd_get(sock);
blocking = (fcntl(fd, F_GETFL, O_NONBLOCK) & O_NONBLOCK) ? TRUE : FALSE;
str = nxo_string_get(nxo);
len = nxo_string_len_get(nxo);
nwritten = 0;
nxo_string_lock(nxo);
nwrite = send(nxo_file_fd_get(sock), nxo_string_get(nxo),
nxo_string_len_get(nxo), flags);
nxo_string_unlock(nxo);

if (nwrite == -1)
do
{
switch (errno)
while ((count = send(fd, &str[nwritten], len - nwritten, flags)) == -1)
{
case EWOULDBLOCK:
{
/* Failed non-blocking write. */
nwrite = 0;
break;
}
case ECONNREFUSED:
case EHOSTDOWN:
case EHOSTUNREACH:
case EMSGSIZE:
case ENOTCONN:
{
nxo_thread_nerror(a_thread, NXN_neterror);
return;
}
case ENOTSOCK:
{
nxo_thread_nerror(a_thread, NXN_argcheck);
return;
}
case EBADF:
case EFAULT:
case ENOBUFS:
case EINTR:
case EINVAL:
case ENOMEM:
case EPIPE:
default:
switch (errno)
{
nxo_thread_nerror(a_thread, NXN_unregistered);
return;
case EINTR:
{
/* Interrupted system call. */
break;
}
case EWOULDBLOCK:
{
/* Failed non-blocking write. */
goto OUT;
}
case ECONNREFUSED:
case EHOSTDOWN:
case EHOSTUNREACH:
case EMSGSIZE:
case ENOTCONN:
{
nxo_string_unlock(nxo);
nxo_thread_nerror(a_thread, NXN_neterror);
return;
}
case ENOTSOCK:
{
nxo_string_unlock(nxo);
nxo_thread_nerror(a_thread, NXN_argcheck);
return;
}
case EBADF:
case EFAULT:
case ENOBUFS:
case EINVAL:
case ENOMEM:
case EPIPE:
default:
{
nxo_string_unlock(nxo);
nxo_thread_nerror(a_thread, NXN_unregistered);
return;
}
}
}
}
nwritten += count;
} while (nwritten < len && blocking);
OUT:
nxo_string_unlock(nxo);

nxo_integer_new(sock, (cw_nxoi_t) nwrite);
nxo_integer_new(sock, (cw_nxoi_t) nwritten);

nxo_stack_npop(ostack, npop);
}
Expand Down Expand Up @@ -12792,7 +12811,14 @@ systemdict_waitpid(cw_nxo_t *a_thread)
}
pid = nxo_integer_get(nxo);

waitpid(pid, &status, 0);
while (waitpid(pid, &status, 0) == -1)
{
if (errno != EINTR)
{
nxo_thread_nerror(a_thread, NXN_unregistered);
return;
}
}
if (WIFEXITED(status))
{
/* Normal program exit. */
Expand Down

0 comments on commit 3789b79

Please sign in to comment.