Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GH #909] Add SO_ and SOL_ definitions, add setsocktopt test
Do not use the g/set_flags vtable interface for g/setsocktopt methods.
Be explicit as it is for sockets only.
  • Loading branch information
Reini Urban committed Jan 8, 2013
1 parent 236f8e3 commit 3f17b60
Show file tree
Hide file tree
Showing 6 changed files with 649 additions and 37 deletions.
105 changes: 104 additions & 1 deletion include/parrot/io.h
Expand Up @@ -76,7 +76,7 @@
* Enum definition of constants for Socket.socket.
* Note that these are the *parrot* values for these defines; the system
* values vary from one platform to the next. See the lookup tables in
* socket_unix.c and socket_win32.c for the mappings.
* src/platform/generic/socket.c for the mappings.
*/

/* &gen_from_enum(socket.pasm) */
Expand All @@ -102,6 +102,109 @@ typedef enum {
PIO_PROTO_TCP = 6,
PIO_PROTO_UDP = 17 /* last element */
} Socket_Protocol;

typedef enum {
PIO_SOL_IP = 0,
PIO_SOL_SOCKET = 1, /* linux, bsd: to the socket itself */
PIO_SOL_TCP = 6, /* bsd, cygwin, linux */
PIO_SOL_UDP = 17, /* bsd, cygwin, linux */
PIO_SOL_IPV6 = 41, /* bsd, cygwin, linux */
PIO_SOL_ICMPV6 = 58, /* linux */
PIO_SOL_IRLMP, /* w32api */
PIO_SOL_RFCOMM, /* w32api */
PIO_SOL_L2CAP, /* w32api */
PIO_SOL_SDP, /* w32api */
PIO_SOL_APPLETALK, /* w32api. see SOL_ATALK on bsd,cygwin */
PIO_SOL_FILTER = 252, /* solaris: for socket filter level */
PIO_SOL_ROUTE = 253, /* solaris: for routing socket level */
PIO_SOL_IPX = 254, /* bsd, cygwin, linux */
PIO_SOL_RAW = 255, /* linux */
PIO_SOL_AX25 = 256, /* bsd, cygwin, linux */
PIO_SOL_ATALK = 257, /* bsd, cygwin, linux. in w32api called SOL_APPLETALK */
PIO_SOL_NETROM = 259, /* bsd, cygwin, linux */
PIO_SOL_DECNET = 261, /* linux */
PIO_SOL_X25 = 262, /* linux */
PIO_SOL_PACKET = 263, /* solaris: for packet level */
PIO_SOL_ATM = 264, /* linux */
PIO_SOL_AAL = 265, /* linux */
PIO_SOL_IRDA = 266, /* linux */
PIO_SOL_TIPC = 271, /* linux */

PIO_SOL_MAX = 272 /* last element */
} Socket_Option_Level;

typedef enum {
/* POSIX */
PIO_SO_DEBUG = 1,
PIO_SO_BROADCAST, /* permit sending of broadcast msgs. SOCK_DGRAM sockets only */
PIO_SO_REUSEADDR, /* allow local address reuse */
PIO_SO_KEEPALIVE, /* keep connections alive */
PIO_SO_LINGER, /* linger on close if data present (in ticks) */
PIO_SO_OOBINLINE, /* leave received OOB data in line */
PIO_SO_SNDBUF, /* send buffer size */
PIO_SO_RCVBUF, /* receive buffer size */
PIO_SO_DONTROUTE, /* just use interface addresses */
PIO_SO_SNDLOWAT, /* send low-water mark */
PIO_SO_RCVLOWAT, /* receive low-water mark */
PIO_SO_SNDTIMEO, /* send timeout */
PIO_SO_RCVTIMEO, /* receive timeout */
PIO_SO_TYPE, /* get socket type */
PIO_SO_ERROR, /* get error status and clear */
/* all other */
PIO_SO_ACCEPTCONN, /* socket has had listen() */
PIO_SO_USELOOPBACK, /* bypass hardware when possible */
PIO_SO_REUSEPORT, /* allow local address & port reuse */
/* solaris */
PIO_SO_DGRAM_ERRIND, /* Solaris: Application wants delayed error */
PIO_SO_RECVUCRED, /* Solaris: Application wants ucred of sender */
PIO_SO_RCVPSH, /* receive interval to push data */
PIO_SO_PROTOTYPE, /* get/set protocol type */
PIO_SO_ANON_MLP, /* create MLP on anonymous bind */
PIO_SO_MAC_EXEMPT, /* allow dominated unlabeled peers */
PIO_SO_PASSIVE_CONNECT, /* do passive connect */
PIO_SO_SECATTR, /* socket's security attributes */
PIO_SO_ALLZONES, /* bind in all zones */
PIO_SO_EXCLBIND, /* exclusive binding */
PIO_SO_MAC_IMPLICIT, /* hide mac labels on wire */
PIO_SO_VRRP, /* VRRP control socket */
/* bsd */
PIO_SO_JUMBO, /* try to use jumbograms */
PIO_SO_BINDANY, /* allow bind to any address */
PIO_SO_NETPROC, /* multiplex; network processing */
PIO_SO_RTABLE, /* routing table to be used */
PIO_SO_SPLICE, /* splice data to other socket */
/* solaris+linux */
PIO_SO_DOMAIN, /* get socket domain */
PIO_SO_TIMESTAMP, /* timestamp received dgram traffic, also bsd */
PIO_SO_TIMESTAMP_MONOTONIC, /* Monotonically increasing timestamp on rcvd dgram */
PIO_SO_ACCEPTFILTER, /* there is an accept filter */
/* apple+linux */
PIO_SO_DONTTRUNC, /* Retain unread data */
PIO_SO_WANTMORE, /* Give hint when more data ready */
PIO_SO_WANTOOBFLAG, /* Want OOB in MSG_FLAG on receive */
/* linux */
PIO_SO_NO_CHECK,
PIO_SO_PRIORITY,
PIO_SO_BSDCOMPAT,
PIO_SO_SECURITY_AUTHENTICATION,
PIO_SO_SECURITY_ENCRYPTION_TRANSPORT,
PIO_SO_SECURITY_ENCRYPTION_NETWORK,
PIO_SO_BINDTODEVICE,
PIO_SO_ATTACH_FILTER,
PIO_SO_DETACH_FILTER,
PIO_SO_PEERNAME,
PIO_SO_PEERSEC,
PIO_SO_PASSSEC,
PIO_SO_TIMESTAMPNS,
PIO_SO_MARK,
PIO_SO_TIMESTAMPING,
PIO_SO_PROTOCOL,
PIO_SO_RXQ_OVFL,
PIO_SO_PASSCRED,
PIO_SO_PEERCRED, /* also bsd: get connect-time credentials */

PIO_SO_MAX, /* last element */
} Socket_Option;
/* &end_gen */

extern PIOOFF_T piooffsetzero;
Expand Down
5 changes: 2 additions & 3 deletions include/parrot/platform_interface.h
Expand Up @@ -111,10 +111,9 @@ INTVAL Parrot_io_internal_send(PARROT_INTERP, PIOHANDLE handle, ARGIN(const char
INTVAL Parrot_io_internal_recv(PARROT_INTERP, PIOHANDLE handle, ARGOUT(char *buf), size_t len);
INTVAL Parrot_io_internal_poll(PARROT_INTERP, PIOHANDLE handle, int which, int sec, int usec);
INTVAL Parrot_io_internal_getsockopt(PARROT_INTERP, PIOHANDLE handle,
ARGIN(INTVAL level), ARGIN(void *option_name), ARGMOD(INTVAL *value));
ARGIN(INTVAL level), ARGIN(INTVAL option), ARGMOD(INTVAL *value));
INTVAL Parrot_io_internal_setsockopt(PARROT_INTERP, PIOHANDLE handle,
ARGIN(INTVAL level), ARGIN(void *option_name), ARGIN(INTVAL value));
void *Parrot_io_internal_socket_optionname(PARROT_INTERP, ARGIN(STRING *name));
ARGIN(INTVAL level), ARGIN(INTVAL option), ARGIN(INTVAL value));
INTVAL Parrot_io_internal_close_socket(PARROT_INTERP, PIOHANDLE handle);

/*
Expand Down
6 changes: 4 additions & 2 deletions src/io/socket.c
Expand Up @@ -498,8 +498,8 @@ flags)>
Set a single socket option via setsockopt() by a bitmasked value of
level, option_name and option_value.
4 bits for level,
4 bits for option_name,
x bits for level,
x bits for option_name,
the rest 24-56 bits for the option_value.
=item C<static INTVAL io_socket_get_flags(PARROT_INTERP, PMC *handle)>
Expand All @@ -519,6 +519,8 @@ io_socket_set_flags(PARROT_INTERP, ARGIN(PMC *handle), INTVAL flags)
GETATTR_Socket_os_handle(interp, handle, os_handle);
/* dissect level, name, value */
Parrot_io_internal_setsockopt(interp, os_handle, 0, 0, 0);
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_NOT_IMPLEMENTED,
"set_flags via single bitmask not available");
}

static INTVAL
Expand Down

0 comments on commit 3f17b60

Please sign in to comment.