Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why no setsockopt / getsockopt? #1

Open
avodonosov opened this issue Dec 12, 2022 · 1 comment
Open

Why no setsockopt / getsockopt? #1

avodonosov opened this issue Dec 12, 2022 · 1 comment

Comments

@avodonosov
Copy link

No description provided.

@ghost
Copy link

ghost commented Dec 14, 2022

(include "sys/types.h")
(include "sys/socket.h")
(include "arpa/inet.h")
(include "netinet/in.h")

(constantenum
      (socket-opt-level :base-type :int :define-constants t)
      ((:sol-socket "SOL_SOCKET")))

(constantenum
     (socket-opt :base-type :int :define-constants t)
     ((:so-reuseaddr "SO_REUSEADDR"))
     ((:so-reuseport "SO_REUSEPORT"))
     ((:so-keepalive "SO_KEEPALIVE"))
     ((:so-linger "SO_LINGER"))
     ((:so-sndbuf "SO_SNDBUF"))
     ((:so-rcvbuf "SO_RCVBUF"))
     ((:so-rcvtimeo "SO_RCVTIMEO"))
     ((:so-sndtimeo "SO_SNDTIMEO")))

(ctype socklen-t "socklen_t")
(defcfun (setsockopt "setsockopt") :int
      (fd :int)
      (level socket-opt-level)
      (optname socket-opt)
      (optval :pointer)
      (optlen socklen-t))

(defun reuse-server (sockfd)
    (with-foreign-object (opt :int)
        (setf (mem-ref opt :int) 1)
        (the integer (setsockopt sockfd :SOL-SOCKET :SO-REUSEADDR opt (foreign-type-size :int)))
        (the integer (setsockopt sockfd :SOL-SOCKET :SO-REUSEPORT opt (foreign-type-size :int)))))
;hope that helps

;https://github.com/cffi-posix/cffi-socket
;https://github.com/mateuszb/socket
;https://github.com/Noeda/m-socket
;https://github.com/fjames86/fsocket

;or use setf with sb-bsd-sockets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant