mirror of
https://github.com/samba-team/samba.git
synced 2025-11-28 12:23:49 +03:00
Get rid of read_socket_with_timeout
This commit is contained in:
@@ -1042,21 +1042,20 @@ NTSTATUS read_socket_with_timeout_ntstatus(int fd, char *buf,
|
|||||||
return NT_STATUS_OK;
|
return NT_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t read_socket_with_timeout(int fd, char *buf,
|
/****************************************************************************
|
||||||
size_t mincnt, size_t maxcnt,
|
Read data from the client, reading exactly N bytes.
|
||||||
unsigned int time_out,
|
****************************************************************************/
|
||||||
enum smb_read_errors *pre)
|
|
||||||
|
ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre)
|
||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
size_t size_ret;
|
|
||||||
|
|
||||||
set_smb_read_error(pre, SMB_READ_OK);
|
set_smb_read_error(pre, SMB_READ_OK);
|
||||||
|
|
||||||
status = read_socket_with_timeout_ntstatus(fd, buf, mincnt, maxcnt,
|
status = read_socket_with_timeout_ntstatus(fd, buffer, N, N, 0, NULL);
|
||||||
time_out, &size_ret);
|
|
||||||
|
|
||||||
if (NT_STATUS_IS_OK(status)) {
|
if (NT_STATUS_IS_OK(status)) {
|
||||||
return size_ret;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
|
if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
|
||||||
@@ -1073,15 +1072,6 @@ ssize_t read_socket_with_timeout(int fd, char *buf,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
Read data from the client, reading exactly N bytes.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
ssize_t read_data(int fd,char *buffer,size_t N, enum smb_read_errors *pre)
|
|
||||||
{
|
|
||||||
return read_socket_with_timeout(fd, buffer, N, N, 0, pre);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Write data to a fd.
|
Write data to a fd.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -1214,7 +1204,6 @@ ssize_t receive_smb_raw(int fd,
|
|||||||
enum smb_read_errors *pre)
|
enum smb_read_errors *pre)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
ssize_t ret;
|
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
set_smb_read_error(pre,SMB_READ_OK);
|
set_smb_read_error(pre,SMB_READ_OK);
|
||||||
@@ -1264,11 +1253,23 @@ ssize_t receive_smb_raw(int fd,
|
|||||||
len = MIN(len,maxlen);
|
len = MIN(len,maxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = read_socket_with_timeout(fd, buffer+4, len, len, timeout,
|
set_smb_read_error(pre, SMB_READ_OK);
|
||||||
pre);
|
|
||||||
|
|
||||||
if (ret != len) {
|
status = read_socket_with_timeout_ntstatus(
|
||||||
cond_set_smb_read_error(pre,SMB_READ_ERROR);
|
fd, buffer+4, len, len, timeout, &len);
|
||||||
|
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
|
||||||
|
set_smb_read_error(pre, SMB_READ_EOF);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
|
||||||
|
set_smb_read_error(pre, SMB_READ_TIMEOUT);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_smb_read_error(pre, SMB_READ_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,8 +180,28 @@ bool cli_receive_smb(struct cli_state *cli)
|
|||||||
|
|
||||||
ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
|
ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
return read_socket_with_timeout(cli->fd, buffer, len, len,
|
NTSTATUS status;
|
||||||
cli->timeout, &cli->smb_rw_error);
|
|
||||||
|
set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
|
||||||
|
|
||||||
|
status = read_socket_with_timeout_ntstatus(
|
||||||
|
cli->fd, buffer, len, len, cli->timeout, NULL);
|
||||||
|
if (NT_STATUS_IS_OK(status)) {
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
|
||||||
|
set_smb_read_error(&cli->smb_rw_error, SMB_READ_EOF);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
|
||||||
|
set_smb_read_error(&cli->smb_rw_error, SMB_READ_TIMEOUT);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -239,7 +239,8 @@ static int dochild(int master, const char *slavedev, const struct passwd *pass,
|
|||||||
static int expect(int master, char *issue, char *expected)
|
static int expect(int master, char *issue, char *expected)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int attempts, timeout, nread, len;
|
int attempts, timeout, nread;
|
||||||
|
size_t len;
|
||||||
bool match = False;
|
bool match = False;
|
||||||
|
|
||||||
for (attempts = 0; attempts < 2; attempts++) {
|
for (attempts = 0; attempts < 2; attempts++) {
|
||||||
@@ -248,7 +249,8 @@ static int expect(int master, char *issue, char *expected)
|
|||||||
DEBUG(100, ("expect: sending [%s]\n", issue));
|
DEBUG(100, ("expect: sending [%s]\n", issue));
|
||||||
|
|
||||||
if ((len = sys_write(master, issue, strlen(issue))) != strlen(issue)) {
|
if ((len = sys_write(master, issue, strlen(issue))) != strlen(issue)) {
|
||||||
DEBUG(2,("expect: (short) write returned %d\n", len ));
|
DEBUG(2,("expect: (short) write returned %d\n",
|
||||||
|
(int)len ));
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,9 +263,16 @@ static int expect(int master, char *issue, char *expected)
|
|||||||
nread = 0;
|
nread = 0;
|
||||||
buffer[nread] = 0;
|
buffer[nread] = 0;
|
||||||
|
|
||||||
while ((len = read_socket_with_timeout(master, buffer + nread, 1,
|
while (True) {
|
||||||
sizeof(buffer) - nread - 1,
|
NTSTATUS status;
|
||||||
timeout, NULL)) > 0) {
|
status = read_socket_with_timeout_ntstatus(
|
||||||
|
master, buffer + nread, 1,
|
||||||
|
sizeof(buffer) - nread - 1,
|
||||||
|
timeout, &len);
|
||||||
|
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
nread += len;
|
nread += len;
|
||||||
buffer[nread] = 0;
|
buffer[nread] = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user