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

s3:rpc_client: add set_timeout hook to rpc_cli_transport

metze
This commit is contained in:
Stefan Metzmacher 2010-03-25 15:51:51 +01:00
parent 4f41b53487
commit 99664ad154
5 changed files with 64 additions and 20 deletions

View File

@ -112,6 +112,7 @@ struct rpc_cli_transport {
uint8_t **prdata, uint32_t *prdata_len);
bool (*is_connected)(void *priv);
unsigned int (*set_timeout)(void *priv, unsigned int timeout);
void *priv;
};

View File

@ -3067,30 +3067,15 @@ NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli,
unsigned int rpccli_set_timeout(struct rpc_pipe_client *rpc_cli,
unsigned int timeout)
{
struct cli_state *cli;
if (rpc_cli->transport->transport == NCACN_NP) {
cli = rpc_pipe_np_smb_conn(rpc_cli);
if (cli == NULL) {
return 0;
}
return cli_set_timeout(cli, timeout);
if (rpc_cli->transport == NULL) {
return 0;
}
if (rpc_cli->transport->transport == NCACN_IP_TCP ||
rpc_cli->transport->transport == NCALRPC) {
return rpccli_set_sock_timeout(rpc_cli, timeout);
if (rpc_cli->transport->set_timeout == NULL) {
return 0;
}
if (rpc_cli->transport->transport == NCACN_INTERNAL) {
cli = rpc_pipe_smbd_smb_conn(rpc_cli);
if (!cli) {
return 0;
}
return cli_set_timeout(cli, timeout);
}
return 0;
return rpc_cli->transport->set_timeout(rpc_cli->transport->priv, timeout);
}
bool rpccli_is_connected(struct rpc_pipe_client *rpc_cli)

View File

@ -47,6 +47,24 @@ static bool rpc_np_is_connected(void *priv)
return true;
}
static unsigned int rpc_np_set_timeout(void *priv, unsigned int timeout)
{
struct rpc_transport_np_state *np_transport = talloc_get_type_abort(
priv, struct rpc_transport_np_state);
bool ok;
if (np_transport->cli == NULL) {
return false;
}
ok = rpc_np_is_connected(np_transport);
if (!ok) {
return 0;
}
return cli_set_timeout(np_transport->cli, timeout);
}
static int rpc_transport_np_state_destructor(struct rpc_transport_np_state *s)
{
if (!rpc_np_is_connected(s)) {
@ -447,6 +465,7 @@ NTSTATUS rpc_transport_np_init_recv(struct tevent_req *req,
state->transport->trans_send = rpc_np_trans_send;
state->transport->trans_recv = rpc_np_trans_recv;
state->transport->is_connected = rpc_np_is_connected;
state->transport->set_timeout = rpc_np_set_timeout;
*presult = talloc_move(mem_ctx, &state->transport);
return NT_STATUS_OK;

View File

@ -464,6 +464,24 @@ static bool rpc_smbd_is_connected(void *priv)
return true;
}
static unsigned int rpc_smbd_set_timeout(void *priv, unsigned int timeout)
{
struct rpc_transport_smbd_state *transp = talloc_get_type_abort(
priv, struct rpc_transport_smbd_state);
bool ok;
ok = rpc_smbd_is_connected(transp);
if (!ok) {
return 0;
}
if (transp->sub_transp->set_timeout == NULL) {
return 0;
}
return transp->sub_transp->set_timeout(transp->sub_transp->priv, timeout);
}
struct rpc_smbd_write_state {
struct rpc_transport_smbd_state *transp;
ssize_t written;
@ -709,6 +727,7 @@ NTSTATUS rpc_transport_smbd_init_recv(struct tevent_req *req,
state->transport->trans_send = NULL;
state->transport->trans_recv = NULL;
state->transport->is_connected = rpc_smbd_is_connected;
state->transport->set_timeout = rpc_smbd_set_timeout;
*presult = talloc_move(mem_ctx, &state->transport);
return NT_STATUS_OK;

View File

@ -53,6 +53,25 @@ static bool rpc_sock_is_connected(void *priv)
return true;
}
static unsigned int rpc_sock_set_timeout(void *priv, unsigned int timeout)
{
struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort(
priv, struct rpc_transport_sock_state);
int orig_timeout;
bool ok;
ok = rpc_sock_is_connected(sock_transp);
if (!ok) {
return 0;
}
orig_timeout = sock_transp->timeout;
sock_transp->timeout = timeout;
return orig_timeout;
}
struct rpc_sock_read_state {
struct rpc_transport_sock_state *transp;
ssize_t received;
@ -241,6 +260,7 @@ NTSTATUS rpc_transport_sock_init(TALLOC_CTX *mem_ctx, int fd,
result->read_send = rpc_sock_read_send;
result->read_recv = rpc_sock_read_recv;
result->is_connected = rpc_sock_is_connected;
result->set_timeout = rpc_sock_set_timeout;
*presult = result;
return NT_STATUS_OK;