Hello,
I noticed that the INET accept method for SOCKET-ACCEPT would return
the socket object as the first value, followed by a vector as the
second value holding the four octets of the client IP address.
However, the port was missing, and to obtain it an extra syscall would
be required, yet accept(2) is designed to also fill the port part of
the sockaddr.
This minor patch adds a third value, the port number. The SBCL
documentation on sb-bsd-sockets:socket-accept also only refers to two
values, but adding a third value should not hurt existing applications,
and seems to be the logical thing to do. I did not check if the actual
SBCL implementation also now does it, but it's possible; it otherwise
would be good to file a bug report for it...
Thanks,
--
Matt
diff --git a/contrib/sockets/sockets.lisp b/contrib/sockets/sockets.lisp
index 78b0b3b..56e56ef 100755
--- a/contrib/sockets/sockets.lisp
+++ b/contrib/sockets/sockets.lisp
@@ -582,8 +582,8 @@ static void fill_inet_sockaddr(struct sockaddr_in
*sockaddr, int port,
(defmethod socket-accept ((socket inet-socket))
(let ((sfd (socket-file-descriptor socket)))
- (multiple-value-bind (fd vector)
- (c-inline (sfd) (:int) (values :int :object)
+ (multiple-value-bind (fd vector port)
+ (c-inline (sfd) (:int) (values :int :object :int)
"{
struct sockaddr_in sockaddr;
socklen_t addr_len = (socklen_t)sizeof(struct sockaddr_in);
@@ -595,6 +595,7 @@ static void fill_inet_sockaddr(struct sockaddr_in
*sockaddr, int port,
@(return 0) = new_fd;
@(return 1) = Cnil;
+ @(return 2) = 0;
if (new_fd != -1) {
uint32_t ip = ntohl(sockaddr.sin_addr.s_addr);
uint16_t port = ntohs(sockaddr.sin_port);
@@ -606,6 +607,7 @@ static void fill_inet_sockaddr(struct sockaddr_in
*sockaddr, int port,
ecl_aset(vector,3, MAKE_FIXNUM( ip & 0xFF ));
@(return 1) = vector;
+ @(return 2) = port;
}
}")
(cond
@@ -617,7 +619,8 @@ static void fill_inet_sockaddr(struct sockaddr_in
*sockaddr, int port,
:type (socket-type socket)
:protocol (socket-protocol socket)
:descriptor fd)
- vector))))))
+ vector
+ port))))))
(defmethod socket-connect ((socket inet-socket) &rest address)
(let ((ip (first address))
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Ecls-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ecls-list