diff options
author | Jeremy Allison <jra@samba.org> | 2009-05-06 15:07:05 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-05-06 15:07:05 -0700 |
commit | 512879a69b6e94c323c37a6c0e56824c097b7f70 (patch) | |
tree | 4673c7f00ae7cb4675f4355b4ed3fbe11145b977 /source3/libsmb | |
parent | 78754ab2c9b28ea8ab09d3fd1f5450abe721a2c1 (diff) | |
download | samba-512879a69b6e94c323c37a6c0e56824c097b7f70.tar.gz samba-512879a69b6e94c323c37a6c0e56824c097b7f70.tar.bz2 samba-512879a69b6e94c323c37a6c0e56824c097b7f70.zip |
Make cli_setattrE async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clifile.c | 120 | ||||
-rw-r--r-- | source3/libsmb/libsmb_file.c | 4 |
2 files changed, 98 insertions, 26 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 357923abcb..7983516f87 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -2391,43 +2391,115 @@ NTSTATUS cli_getatr(struct cli_state *cli, Do a SMBsetattrE call. ****************************************************************************/ -bool cli_setattrE(struct cli_state *cli, int fd, - time_t change_time, - time_t access_time, - time_t write_time) +static void cli_setattrE_done(struct tevent_req *subreq); +struct cli_setattrE_state { + int dummy; +}; + +struct tevent_req *cli_setattrE_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time) { - char *p; + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_setattrE_state *state = NULL; + uint8_t additional_flags = 0; + uint16_t vwv[7]; - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); + req = tevent_req_create(mem_ctx, &state, struct cli_setattrE_state); + if (req == NULL) { + return NULL; + } - cli_set_message(cli->outbuf,7,0,True); + memset(vwv, '\0', sizeof(vwv)); + SSVAL(vwv+0, 0, fnum); + cli_put_dos_date2(cli, (char *)&vwv[1], 0, change_time); + cli_put_dos_date2(cli, (char *)&vwv[3], 0, access_time); + cli_put_dos_date2(cli, (char *)&vwv[5], 0, write_time); - SCVAL(cli->outbuf,smb_com,SMBsetattrE); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); + subreq = cli_smb_send(state, ev, cli, SMBsetattrE, additional_flags, + 7, vwv, 0, NULL); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_setattrE_done, req); + return req; +} - SSVAL(cli->outbuf,smb_vwv0, fd); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv1, change_time); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv3, access_time); - cli_put_dos_date2(cli, cli->outbuf,smb_vwv5, write_time); +static void cli_setattrE_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + NTSTATUS status; - p = smb_buf(cli->outbuf); - *p++ = 4; + status = cli_smb_recv(subreq, 0, NULL, NULL, NULL, NULL); + TALLOC_FREE(subreq); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + tevent_req_done(req); +} - cli_setup_bcc(cli, p); +NTSTATUS cli_setattrE_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return False; +NTSTATUS cli_setattrE(struct cli_state *cli, + uint16_t fnum, + time_t change_time, + time_t access_time, + time_t write_time) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev = NULL; + struct tevent_req *req = NULL; + NTSTATUS status = NT_STATUS_OK; + + if (cli_has_async_calls(cli)) { + /* + * Can't use sync call while an async call is in flight + */ + status = NT_STATUS_INVALID_PARAMETER; + goto fail; } - if (cli_is_error(cli)) { - return False; + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; } - return True; + req = cli_setattrE_send(frame, ev, + cli, + fnum, + change_time, + access_time, + write_time); + + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; + } + + status = cli_setattrE_recv(req); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index 63590d2fdf..1bb12123a5 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -669,10 +669,10 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, } /* Set the new attributes */ - ret = cli_setattrE(srv->cli, fd, + ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd, change_time, access_time, - write_time); + write_time)); /* Close the file */ cli_close(srv->cli, fd); |