svn commit: samba r7227 - in branches/SAMBA_4_0/source/lib/socket: .
tridge at samba.org
tridge at samba.org
Fri Jun 3 13:20:10 GMT 2005
Author: tridge
Date: 2005-06-03 13:20:08 +0000 (Fri, 03 Jun 2005)
New Revision: 7227
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7227
Log:
added a socket_pending() call to abstract away the FIONREAD ioctl. It
will be interesting to see if this causes any portability problems, as
it is a less commonly used call.
Modified:
branches/SAMBA_4_0/source/lib/socket/socket.c
branches/SAMBA_4_0/source/lib/socket/socket.h
branches/SAMBA_4_0/source/lib/socket/socket_ipv4.c
branches/SAMBA_4_0/source/lib/socket/socket_unix.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/socket/socket.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket.c 2005-06-03 13:04:44 UTC (rev 7226)
+++ branches/SAMBA_4_0/source/lib/socket/socket.c 2005-06-03 13:20:08 UTC (rev 7227)
@@ -235,6 +235,22 @@
return sock->ops->fn_sendto(sock, blob, sendlen, flags, dest_addr, dest_port);
}
+
+/*
+ ask for the number of bytes in a pending incoming datagram
+*/
+NTSTATUS socket_pending(struct socket_context *sock, size_t *npending)
+{
+ if (sock->type != SOCKET_TYPE_DGRAM) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ if (!sock->ops->fn_pending) {
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+ return sock->ops->fn_pending(sock, npending);
+}
+
+
NTSTATUS socket_set_option(struct socket_context *sock, const char *option, const char *val)
{
if (!sock->ops->fn_set_option) {
Modified: branches/SAMBA_4_0/source/lib/socket/socket.h
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket.h 2005-06-03 13:04:44 UTC (rev 7226)
+++ branches/SAMBA_4_0/source/lib/socket/socket.h 2005-06-03 13:20:08 UTC (rev 7227)
@@ -60,6 +60,7 @@
NTSTATUS (*fn_recvfrom)(struct socket_context *sock,
void *buf, size_t wantlen, size_t *nread, uint32_t flags,
const char **src_addr, int *src_port);
+ NTSTATUS (*fn_pending)(struct socket_context *sock, size_t *npending);
void (*fn_close)(struct socket_context *sock);
@@ -124,6 +125,7 @@
NTSTATUS socket_sendto(struct socket_context *sock,
const DATA_BLOB *blob, size_t *sendlen, uint32_t flags,
const char *dest_addr, int dest_port);
+NTSTATUS socket_pending(struct socket_context *sock, size_t *npending);
NTSTATUS socket_set_option(struct socket_context *sock, const char *option, const char *val);
char *socket_get_peer_name(struct socket_context *sock, TALLOC_CTX *mem_ctx);
char *socket_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
Modified: branches/SAMBA_4_0/source/lib/socket/socket_ipv4.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket_ipv4.c 2005-06-03 13:04:44 UTC (rev 7226)
+++ branches/SAMBA_4_0/source/lib/socket/socket_ipv4.c 2005-06-03 13:20:08 UTC (rev 7227)
@@ -435,6 +435,16 @@
return sock->fd;
}
+static NTSTATUS ipv4_pending(struct socket_context *sock, size_t *npending)
+{
+ int value = 0;
+ if (ioctl(sock->fd, FIONREAD, &value) == 0) {
+ *npending = value;
+ return NT_STATUS_OK;
+ }
+ return map_nt_error_from_unix(errno);
+}
+
static const struct socket_ops ipv4_ops = {
.name = "ipv4",
.fn_init = ipv4_init,
@@ -446,6 +456,7 @@
.fn_recvfrom = ipv4_recvfrom,
.fn_send = ipv4_send,
.fn_sendto = ipv4_sendto,
+ .fn_pending = ipv4_pending,
.fn_close = ipv4_close,
.fn_set_option = ipv4_set_option,
Modified: branches/SAMBA_4_0/source/lib/socket/socket_unix.c
===================================================================
--- branches/SAMBA_4_0/source/lib/socket/socket_unix.c 2005-06-03 13:04:44 UTC (rev 7226)
+++ branches/SAMBA_4_0/source/lib/socket/socket_unix.c 2005-06-03 13:20:08 UTC (rev 7227)
@@ -316,6 +316,16 @@
return sock->fd;
}
+static NTSTATUS unixdom_pending(struct socket_context *sock, size_t *npending)
+{
+ int value = 0;
+ if (ioctl(sock->fd, FIONREAD, &value) == 0) {
+ *npending = value;
+ return NT_STATUS_OK;
+ }
+ return map_nt_error_from_unix(errno);
+}
+
static const struct socket_ops unixdom_ops = {
.name = "unix",
.fn_init = unixdom_init,
@@ -327,6 +337,7 @@
.fn_send = unixdom_send,
.fn_sendto = unixdom_sendto,
.fn_close = unixdom_close,
+ .fn_pending = unixdom_pending,
.fn_set_option = unixdom_set_option,
More information about the samba-cvs
mailing list