diff options
author | Gary Houston <ghouston@arglist.com> | 2001-01-08 23:10:06 +0000 |
---|---|---|
committer | Gary Houston <ghouston@arglist.com> | 2001-01-08 23:10:06 +0000 |
commit | 60d02d0914b57ba7e1ecd78a9ec27387cfd98b57 (patch) | |
tree | c3671b6c1f6d449539b78c6e419058c17ad6aa6c /libguile/socket.c | |
parent | 264e9cbc9317f94fe29a89fad6f2b5d617f0be27 (diff) | |
download | guile-60d02d0914b57ba7e1ecd78a9ec27387cfd98b57.tar.gz |
* validate.h (SCM_VALIDATE_SUBSTRING_SPEC_COPY): new macro.
* ioext.c (scm_read_string_x_partial, scm_read_delimited_x),
socket.c (scm_recvfrom): use the new macro, plus minor docstring
changes.
* ioext.c (scm_read_string_x_partial): don't crash if -1 is supplied
for fdes. if current input port is used, check that it's a file
port.
Diffstat (limited to 'libguile/socket.c')
-rw-r--r-- | libguile/socket.c | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/libguile/socket.c b/libguile/socket.c index 23f44851d..fc306a321 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -746,12 +746,12 @@ SCM_DEFINE (scm_send, "send", 2, 1, 0, #undef FUNC_NAME SCM_DEFINE (scm_recvfrom, "recvfrom!", 2, 3, 0, - (SCM sock, SCM buf, SCM flags, SCM start, SCM end), + (SCM sock, SCM str, SCM flags, SCM start, SCM end), "Returns data from the socket port @var{socket} and also information about\n" "where the data was received from. @var{socket} must already\n" "be bound to the address from which data is to be received.\n" - "@code{buf}, is a string into which\n" - "the data will be written. The size of @var{buf} limits the amount of\n" + "@code{str}, is a string into which\n" + "the data will be written. The size of @var{str} limits the amount of\n" "data which can be received: in the case of packet\n" "protocols, if a packet larger than this limit is encountered then some data\n" "will be irrevocably lost.\n\n" @@ -760,7 +760,7 @@ SCM_DEFINE (scm_recvfrom, "recvfrom!", 2, 3, 0, "The value returned is a pair: the CAR is the number of bytes read from\n" "the socket and the CDR an address object in the same form as returned by\n" "@code{accept}.\n\n" - "The @var{start} and @var{end} arguments specify a substring of @var{buf}\n" + "The @var{start} and @var{end} arguments specify a substring of @var{str}\n" "to which the data should be written.\n\n" "Note that the data is read directly from the socket file descriptor:\n" "any unread buffered port data is ignored.") @@ -769,44 +769,23 @@ SCM_DEFINE (scm_recvfrom, "recvfrom!", 2, 3, 0, int rv; int fd; int flg; - int offset = 0; + char *buf; + int offset; int cend; size_t tmp_size; SCM address; SCM_VALIDATE_OPFPORT (1,sock); - SCM_VALIDATE_STRING (2,buf); - cend = SCM_STRING_LENGTH (buf); - + fd = SCM_FPORT_FDES (sock); + SCM_VALIDATE_SUBSTRING_SPEC_COPY (2, str, buf, 4, start, offset, + 5, end, cend); if (SCM_UNBNDP (flags)) flg = 0; else - { - flg = SCM_NUM2ULONG (3,flags); - - if (!SCM_UNBNDP (start)) - { - offset = (int) SCM_NUM2LONG (4,start); - - if (offset < 0 || offset >= cend) - SCM_OUT_OF_RANGE (4, start); - - if (!SCM_UNBNDP (end)) - { - int tend = (int) SCM_NUM2LONG (5,end); - - if (tend <= offset || tend > cend) - SCM_OUT_OF_RANGE (5, end); - - cend = tend; - } - } - } - - fd = SCM_FPORT_FDES (sock); + SCM_VALIDATE_ULONG_COPY (3, flags, flg); tmp_size = scm_addr_buffer_size; - SCM_SYSCALL (rv = recvfrom (fd, SCM_STRING_CHARS (buf) + offset, + SCM_SYSCALL (rv = recvfrom (fd, buf + offset, cend - offset, flg, (struct sockaddr *) scm_addr_buffer, &tmp_size)); |