smb_panic("Unable to allocate messaging_rec");
}
- status = socket_accept(msg->sock, &rec->sock, 0);
+ status = socket_accept(msg->sock, &rec->sock);
if (!NT_STATUS_IS_OK(status)) {
smb_panic("Unable to accept messaging_rec");
}
return status;
}
+ /* by enabling "testnonblock" mode, all socket receive and
+ send calls on non-blocking sockets will randomly recv/send
+ less data than requested */
+ if (!(flags & SOCKET_FLAG_BLOCK) &&
+ lp_parm_bool(-1, "socket", "testnonblock", False)) {
+ (*new_sock)->flags |= SOCKET_FLAG_TESTNONBLOCK;
+ }
+
talloc_set_destructor(*new_sock, socket_destructor);
return NT_STATUS_OK;
return sock->ops->listen(sock, my_address, port, queue_size, flags);
}
-NTSTATUS socket_accept(struct socket_context *sock, struct socket_context **new_sock, uint32_t flags)
+NTSTATUS socket_accept(struct socket_context *sock, struct socket_context **new_sock)
{
NTSTATUS status;
return NT_STATUS_NOT_IMPLEMENTED;
}
- status = sock->ops->accept(sock, new_sock, flags);
+ status = sock->ops->accept(sock, new_sock);
if (NT_STATUS_IS_OK(status)) {
talloc_set_destructor(*new_sock, socket_destructor);
return NT_STATUS_NOT_IMPLEMENTED;
}
+ if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK) && wantlen > 1) {
+ return sock->ops->recv(sock, buf, 1+(random() % (wantlen-1)), nread, flags);
+ }
+
return sock->ops->recv(sock, buf, wantlen, nread, flags);
}
return NT_STATUS_NOT_IMPLEMENTED;
}
+ if ((sock->flags & SOCKET_FLAG_TESTNONBLOCK) && blob->length > 1) {
+ DATA_BLOB blob2 = *blob;
+ blob2.length = 1+(random() % (blob2.length-1));
+ return sock->ops->send(sock, &blob2, sendlen, flags);
+ }
+
return sock->ops->send(sock, blob, sendlen, flags);
}
/* server ops */
NTSTATUS (*listen)(struct socket_context *sock,
const char *my_address, int port, int queue_size, uint32_t flags);
- NTSTATUS (*accept)(struct socket_context *sock,
- struct socket_context **new_sock, uint32_t flags);
+ NTSTATUS (*accept)(struct socket_context *sock, struct socket_context **new_sock);
/* general ops */
NTSTATUS (*recv)(struct socket_context *sock, void *buf,
SOCKET_STATE_SERVER_ERROR
};
-#define SOCKET_FLAG_BLOCK 0x00000001
-#define SOCKET_FLAG_PEEK 0x00000002
+#define SOCKET_FLAG_BLOCK 0x00000001
+#define SOCKET_FLAG_PEEK 0x00000002
+#define SOCKET_FLAG_TESTNONBLOCK 0x00000004
struct socket_context {
enum socket_type type;
return NT_STATUS_OK;
}
-static NTSTATUS ipv4_tcp_accept(struct socket_context *sock, struct socket_context **new_sock, uint32_t flags)
+static NTSTATUS ipv4_tcp_accept(struct socket_context *sock, struct socket_context **new_sock)
{
struct sockaddr_in cli_addr;
socklen_t cli_addr_len = sizeof(cli_addr);
return map_nt_error_from_unix(errno);
}
- if (!(flags & SOCKET_FLAG_BLOCK)) {
+ if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, False);
if (ret == -1) {
close(new_fd);
/* copy the socket_context */
(*new_sock)->type = sock->type;
(*new_sock)->state = SOCKET_STATE_SERVER_CONNECTED;
- (*new_sock)->flags = flags;
+ (*new_sock)->flags = sock->flags;
(*new_sock)->fd = new_fd;
}
static NTSTATUS unixdom_accept(struct socket_context *sock,
- struct socket_context **new_sock,
- uint32_t flags)
+ struct socket_context **new_sock)
{
struct sockaddr_un cli_addr;
socklen_t cli_addr_len = sizeof(cli_addr);
return unixdom_error(errno);
}
- if (!(flags & SOCKET_FLAG_BLOCK)) {
+ if (!(sock->flags & SOCKET_FLAG_BLOCK)) {
int ret = set_blocking(new_fd, False);
if (ret == -1) {
close(new_fd);
/* copy the socket_context */
(*new_sock)->type = sock->type;
(*new_sock)->state = SOCKET_STATE_SERVER_CONNECTED;
- (*new_sock)->flags = flags;
+ (*new_sock)->flags = sock->flags;
(*new_sock)->fd = new_fd;
struct server_connection *conn;
/* accept an incoming connection. */
- status = socket_accept(server_socket->socket, &sock, 0);
+ status = socket_accept(server_socket->socket, &sock);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("accept_connection_single: accept: %s\n",
nt_errstr(status)));
pid_t pid;
/* accept an incoming connection. */
- status = socket_accept(server_socket->socket, &sock, 0);
+ status = socket_accept(server_socket->socket, &sock);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("standard_accept_connection: accept: %s\n",
nt_errstr(status)));
struct server_connection *conn;
/* accept an incoming connection. */
- status = socket_accept(server_socket->socket, &sock, 0);
+ status = socket_accept(server_socket->socket, &sock);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("accept_connection_single: accept: %s\n",
nt_errstr(status)));