1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

read_socket_with_timeout has timeout=0 handling

This commit is contained in:
Volker Lendecke 2008-01-23 16:42:31 +01:00
parent fd34ce4370
commit 7101026061
3 changed files with 9 additions and 67 deletions

View File

@ -1054,44 +1054,7 @@ ssize_t read_socket_with_timeout(int fd,
ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre)
{
ssize_t ret;
size_t total=0;
char addr[INET6_ADDRSTRLEN];
set_smb_read_error(pre,SMB_READ_OK);
while (total < N) {
ret = sys_read(fd,buffer + total,N - total);
if (ret == 0) {
DEBUG(10,("read_data: read of %d returned 0. "
"Error = %s\n",
(int)(N - total), strerror(errno) ));
set_smb_read_error(pre,SMB_READ_EOF);
return 0;
}
if (ret == -1) {
if (fd == get_client_fd()) {
/* Try and give an error message saying
* what client failed. */
DEBUG(0,("read_data: read failure for %d "
"bytes to client %s. Error = %s\n",
(int)(N - total),
get_peer_addr(fd,addr,sizeof(addr)),
strerror(errno) ));
} else {
DEBUG(0,("read_data: read failure for %d. "
"Error = %s\n",
(int)(N - total),
strerror(errno) ));
}
set_smb_read_error(pre,SMB_READ_ERROR);
return -1;
}
total += ret;
}
return (ssize_t)total;
return read_socket_with_timeout(fd, buffer, N, N, 0, pre);
}
/****************************************************************************

View File

@ -180,12 +180,8 @@ bool cli_receive_smb(struct cli_state *cli)
ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
{
if (cli->timeout > 0) {
return read_socket_with_timeout(cli->fd, buffer, len,
len, cli->timeout, &cli->smb_rw_error);
} else {
return read_data(cli->fd, buffer, len, &cli->smb_rw_error);
}
return read_socket_with_timeout(cli->fd, buffer, len, len,
cli->timeout, &cli->smb_rw_error);
}
/****************************************************************************

View File

@ -155,16 +155,8 @@ static ssize_t read_packet_remainder(int fd,
return len;
}
if (timeout > 0) {
ret = read_socket_with_timeout(fd,
buffer,
len,
len,
timeout,
get_srv_read_error());
} else {
ret = read_data(fd, buffer, len, get_srv_read_error());
}
ret = read_socket_with_timeout(fd, buffer, len, len, timeout,
get_srv_read_error());
if (ret != len) {
cond_set_smb_read_error(get_srv_read_error(),
@ -206,19 +198,10 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx,
memcpy(writeX_header, lenbuf, sizeof(lenbuf));
if (timeout > 0) {
ret = read_socket_with_timeout(fd,
writeX_header + 4,
STANDARD_WRITE_AND_X_HEADER_SIZE,
STANDARD_WRITE_AND_X_HEADER_SIZE,
timeout,
get_srv_read_error());
} else {
ret = read_data(fd,
writeX_header+4,
STANDARD_WRITE_AND_X_HEADER_SIZE,
get_srv_read_error());
}
ret = read_socket_with_timeout(fd, writeX_header + 4,
STANDARD_WRITE_AND_X_HEADER_SIZE,
STANDARD_WRITE_AND_X_HEADER_SIZE,
timeout, get_srv_read_error());
if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) {
cond_set_smb_read_error(get_srv_read_error(),