summaryrefslogtreecommitdiffstats
path: root/socket.c
Commit message (Collapse)AuthorAgeFilesLines
* Mac OS X: must clear sockaddr in order to bind.Kaz Kylheku2016-03-101-0/+2
| | | | | | | | | | Undocumented members in struct sockaddr_in, and possibly sockaddr_in6 also, must be cleared to all zero bits, otherwise bind fails for the loopback address, even if the relevant addressing members are correctly set. * socket.c (sockaddr_in): memset the IPv4 or IPv6 address to zero before filing it.
* Solaris: cannot sendto on connected dgram socket.Kaz Kylheku2016-03-101-2/+8
| | | | | | | | * socket.c (struct dgram_stream): New member, sock_connected. (make_dgram_sock_stream): Initialize sock_connected to zero. (dgram_flush): Use send if sock_connected is nonzero, otherwise sendto. (dgram_set_sock_peer): Set sock_connected to 1.
* Diagnose operations on closed socket.Kaz Kylheku2016-03-071-23/+42
| | | | | * socket.c (sock_bind, sock_connect, sock_listen, sock_accept): If the socket is closed, throw an error.
* Revamped naming for socket streams.Kaz Kylheku2016-03-071-5/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * socket.c (struct dgram_stream): New member, addr. (make_dgram_sock_stream): Initialize addr to nil. (dgram_print): Instead of printing the numeric fd, print the stream description, obtained from the name_k property. (dgram_mark): Mark the addr member. (dgram_get_prop): Calculate a descriptive string from the dgram stream state for the name_k property. (dgram_set_prop): New static function. (dgram_strm_ops): Name change to dgram-sock. Wire in dgram_set_prop function. (sock_bind): Set the addr_k property of the stream to the local address that was just bound. * stream.c (addr_k): New keyword symbol variable. (stdio_handle): New member, addr. (stdio_stream_print): Obtain descr by calling get_prop method rather than directly from h->descr, in case it is dynamically computed. Use ~a rather than ~s for incorporating string properties into printed form, to eliminate quotes. (stdio_stream_mark): Mark new addr member. (sock_get_prop, sock_set_prop): New static functions. (stdio_set_sock_peer): Invalidate h->descr by setting it to nil. (make_stdio_stream_common): Initialize h->addr to nil. (make_sock_stream): Specify description as nil rather than "socket". (stream_init): Intern the addr keyword, and initialize the addr_k variable. Set the name of stdio_sock_ops to "stream-sock" rather than leaving it inherited as "file-stream". Wire in the sock_get_prop and sock_set_prop functions into stdio_sock_ops. * stream.h (addr_k): Declared.
* sock_accept: uninitialized socklen_t.Kaz Kylheku2016-03-071-1/+1
| | | | | * socket.c (sock_accept): The address length passed to recvfrom was not initialized to the storage length.
* gc bugs: more instances of wrong mutations.Kaz Kylheku2016-03-071-1/+1
| | | | | | | | * socket.c (dgram_set_sock_peer): Assign to struct dgram_stream using using set macro. * stream.c (stdio_set_sock_peer): Assign to struct stdio_handle peer using set macro.
* Show failing address in sock-connect error.Kaz Kylheku2016-03-071-2/+2
| | | | | * socket.c (sock_connect): If connect fails, show socket and address in error message.
* Special implementation of dgram socket streams.Kaz Kylheku2016-03-061-28/+488
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * socket.c (struct dgram_stream): New struct. (make_dgram_sock_stream, dgram_print, dgram_mark, dgram_destroy, dgram_overflow, dgram_put_byte_callback, dgram_put_string, dgram_put_char, dgram_put_byte, dgram_get_byte_callback, dgram_get_char, dgram_get_byte, dgram_unget_char, dgram_unget_byte, dgram_flush, dgram_close, dgram_get_prop, dgram_get_fd, dgram_get_sock_family, dgram_get_sock_type, dgram_get_sock_peer, dgram_set_sock_peer, dgram_get_error, dgram_get_error_str, dgram_clear_error): New static functions. (dgram_strm_ops): New static structure. (sock_listen): Check against datagram sockets which have a peer; otherwise a no-op for datagram sockets. (sock_accept): Special logic for dgram sockets. (open_sockfd): Function moved here from stream.c, and augmented to open dgram stream for dgram sockets. (open_socket): Function moved here from stream.c. (sock_load_init): Fill in some operations in dgram_strm_ops. * stream.c (generic_get_line, make_sock_stream, errno_to_string): Statics become external. (open_sockfd, open_socket): Functions removed from here, moved to socket.c. * stream.h (generic_get_line, make_sock_stream, errno_to_string): Declared.
* Refer to correct socket function names in errors.Kaz Kylheku2016-03-061-3/+3
| | | | | | * socket.c (sock_bind, sock_connect, sock_listen): Report function name as sock-bind, sock-connect and sock-listen, rather than bind, connect and listen.
* Socket streams know their connected peer address.Kaz Kylheku2016-02-271-0/+2
| | | | | | | | | | | | * stream.c (struct stdio_handle): New member, peer. (stdio_stream_mark): Mark the new member. (sock_peer, sock_set_peer): New functions. (stream_init): Registered sock-peer intrinsic. * stream.h (sock_peer, sock_set_peer): Declared. * socket.c (sock_connect): If the connect is successful, then store the address into the stream as the peer.
* Do the SO_REUSEADDR thing when binding socket.Kaz Kylheku2016-02-271-2/+5
| | | | | * socket.c (sock_bind): Set the SO_REUSEADDR option before binding the socket, to thwart the EADDRINUSE nuisance.
* Adding socket support: unix, ipv4, ipv6.Kaz Kylheku2016-02-261-0/+382
* socket.c, socket.h: New files. * Makefile: include new socket.o among objects if have_objects variable is defined to 'y'. * configure (have_sockets): New variable. New configure test for socket-related functionality. (HAVE_SOCKETS, HAVE_GETADDRINFO): New configuration preprocessor symbols. Also, reordering the shell probing so that /usr/xpg4/bin/sh is the last fallback. On Solaris, it chokes on some code that is needed for Solaris. * lisplib.c (sock_set_entries, sock_instantiate): New static functions. (lisplib_init): Register new functions as autoload hooks. * share/txr/stdlib/socket.tl: New file. * stream.c (socket_error_s): New symbol variable. (struct stdio_handle): New members, family and type, helping stdio streams represent sockets too. (stdio_stream_mark): Mark new members of struct stdio_handle. (make_stdio_stream_common): Initialize new members. (make_sock_stream, stream_fd, sock_family, sock_type, open_socket, open_sockfd): New functions. (stream_init): Initialize socket_error_s variable. Register sock-family, sock-type and open-socket intrinsic functions. Register socket-error subtype. * stream.h (socket_error_s, make_sock_stream, stream_fd, sock_family, sock_type, open_socket, open_sockfd): Declared.