connection: Allow users to pass extra SOCK_ flags to 'socket'. In particular, this lets users pass SOCK_NONBLOCK. * netlink/connection.scm (open-socket): Add 'flags' parameter and honor it. (connect): Add #:flags and pass it to 'open-socket'. (connect-route): Add #:flags and pass it to 'connect'. * doc/guile-netlink.texi (Netlink Connections): Adjust accordingly. Signed-off-by: Julien Lepiller <julien@lepiller.eu>
doc/guile-netlink.texi
| 240 | 240 | the set of broadcast groups to which the connection subscribes. | |
| 241 | 241 | @end deffn | |
| 242 | 242 | ||
| 243 | - | @deffn {Scheme Procedure} connect @var{proto} @var{addr} | |
| 243 | + | @cindex non-blocking socket | |
| 244 | + | @deffn {Scheme Procedure} connect @var{proto} @var{addr} [#:flags 0] | |
| 244 | 245 | Creates a netlink socket for @var{proto} and binds it to @var{addr}. | |
| 245 | 246 | ||
| 246 | 247 | @var{proto} is the integer representing the protocol. For instance, rtnetlink | |
… | |||
| 248 | 249 | @code{(netlink constant)}). | |
| 249 | 250 | ||
| 250 | 251 | @var{addr} is a bytevector, as returned by @code{get-addr}. | |
| 252 | + | ||
| 253 | + | @var{flags} is a set of additional flags to pass as the second argument | |
| 254 | + | to the @code{socket} system call---e.g., @code{SOCK_NONBLOCK}. | |
| 251 | 255 | @end deffn | |
| 252 | 256 | ||
| 253 | - | @deffn {Scheme Procedure} connect-route [#:groups @code{0}] | |
| 257 | + | @deffn {Scheme Procedure} connect-route [#:groups 0] [#:flags 0] | |
| 254 | 258 | This procedure is a wrapper for @code{connect} that creates a socket for the | |
| 255 | 259 | rtnetlink protocol, binds it to the kernel and returns it. By passing the | |
| 256 | 260 | optional @var{groups} keyword, you can select broadcast groups to subscribe to. | |
| 261 | + | ||
| 262 | + | @var{flags} is a set of additional flags to pass as the second argument | |
| 263 | + | to the @code{socket} system call---e.g., @code{SOCK_NONBLOCK}. | |
| 257 | 264 | @end deffn | |
| 258 | 265 | ||
| 259 | 266 | @deffn {Scheme Procedure} send-msg @var{msg} @var{sock} [#:@var{addr}] | |
netlink/connection.scm
| 74 | 74 | #:waiter (lambda () (current-read-waiter)))) | |
| 75 | 75 | ||
| 76 | 76 | ;; define simple functions to open/close sockets | |
| 77 | - | (define (open-socket proto) | |
| 78 | - | (socket AF_NETLINK (logior SOCK_RAW SOCK_CLOEXEC) proto)) | |
| 77 | + | (define (open-socket proto flags) | |
| 78 | + | (socket AF_NETLINK (logior SOCK_RAW SOCK_CLOEXEC flags) proto)) | |
| 79 | 79 | ||
| 80 | 80 | (define (close-socket sock) | |
| 81 | 81 | (issue-deprecation-warning | |
… | |||
| 102 | 102 | (list '* size_t) | |
| 103 | 103 | (list content size))) | |
| 104 | 104 | ||
| 105 | - | (define* (connect proto addr) | |
| 106 | - | (let ((sock (open-socket proto))) | |
| 105 | + | (define* (connect proto addr #:key (flags 0)) | |
| 106 | + | (let ((sock (open-socket proto flags))) | |
| 107 | 107 | (ffi-bind sock | |
| 108 | 108 | (bytevector->pointer addr) | |
| 109 | 109 | 12) | |
| 110 | 110 | sock)) | |
| 111 | 111 | ||
| 112 | - | (define* (connect-route #:key (groups 0)) | |
| 113 | - | (connect NETLINK_ROUTE (get-addr AF_NETLINK 0 groups))) | |
| 112 | + | (define* (connect-route #:key (groups 0) (flags 0)) | |
| 113 | + | (connect NETLINK_ROUTE (get-addr AF_NETLINK 0 groups) | |
| 114 | + | #:flags flags)) | |
| 114 | 115 | ||
| 115 | 116 | (define* (send-msg msg sock #:key (addr (get-addr AF_NETLINK 0 0))) | |
| 116 | 117 | (unless (message? msg) | |