summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-01-31 14:43:06 +0100
committerVolker Lendecke <vl@samba.org>2009-01-31 17:50:18 +0100
commit2d5ec28b3b065940cefdd491ad7c8fd1a58c3a5c (patch)
treece66ad6ab630cd64ea5e28736bbe3249d8372655 /source3
parent8ef92f7e32af73d0cd215e8f259ba5fcd3d9812e (diff)
downloadsamba-2d5ec28b3b065940cefdd491ad7c8fd1a58c3a5c.tar.gz
samba-2d5ec28b3b065940cefdd491ad7c8fd1a58c3a5c.tar.bz2
samba-2d5ec28b3b065940cefdd491ad7c8fd1a58c3a5c.zip
Make reply_pipe_write async
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/pipes.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c
index 693db521e7..abbcf67d55 100644
--- a/source3/smbd/pipes.c
+++ b/source3/smbd/pipes.c
@@ -144,13 +144,18 @@ void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req)
Reply to a write on a pipe.
****************************************************************************/
+struct pipe_write_state {
+ size_t numtowrite;
+};
+
+static void pipe_write_done(struct async_req *subreq);
+
void reply_pipe_write(struct smb_request *req)
{
files_struct *fsp = file_fsp(req, SVAL(req->vwv+0, 0));
- size_t numtowrite = SVAL(req->vwv+1, 0);
- ssize_t nwritten;
const uint8_t *data;
- NTSTATUS status;
+ struct pipe_write_state *state;
+ struct async_req *subreq;
if (!fsp_is_np(fsp)) {
reply_doserror(req, ERRDOS, ERRbadfid);
@@ -162,29 +167,59 @@ void reply_pipe_write(struct smb_request *req)
return;
}
+ state = talloc(req, struct pipe_write_state);
+ if (state == NULL) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ return;
+ }
+ req->async_priv = state;
+
+ state->numtowrite = SVAL(req->vwv+1, 0);
+
data = req->buf + 3;
DEBUG(6, ("reply_pipe_write: %x name: %s len: %d\n", (int)fsp->fnum,
- fsp->fsp_name, (int)numtowrite));
- status = np_write(fsp->fake_file_handle, data, numtowrite, &nwritten);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
+ fsp->fsp_name, (int)state->numtowrite));
+
+ subreq = np_write_send(state, smbd_event_context(),
+ fsp->fake_file_handle, data, state->numtowrite);
+ if (subreq == NULL) {
+ TALLOC_FREE(state);
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
return;
}
+ subreq->async.fn = pipe_write_done;
+ subreq->async.priv = talloc_move(req->conn, &req);
+}
+
+static void pipe_write_done(struct async_req *subreq)
+{
+ struct smb_request *req = talloc_get_type_abort(
+ subreq->async.priv, struct smb_request);
+ struct pipe_write_state *state = talloc_get_type_abort(
+ req->async_priv, struct pipe_write_state);
+ NTSTATUS status;
+ ssize_t nwritten = -1;
- if ((nwritten == 0 && numtowrite != 0) || (nwritten < 0)) {
+ status = np_write_recv(subreq, &nwritten);
+ TALLOC_FREE(subreq);
+ if ((nwritten == 0 && state->numtowrite != 0) || (nwritten < 0)) {
reply_unixerror(req, ERRDOS, ERRnoaccess);
- return;
+ goto send;
}
reply_outbuf(req, 1, 0);
SSVAL(req->outbuf,smb_vwv0,nwritten);
-
- DEBUG(3,("write-IPC pnum=%04x nwritten=%d\n", fsp->fnum,
- (int)nwritten));
- return;
+ DEBUG(3,("write-IPC nwritten=%d\n", (int)nwritten));
+
+ send:
+ if (!srv_send_smb(smbd_server_fd(), (char *)req->outbuf,
+ IS_CONN_ENCRYPTED(req->conn)||req->encrypted)) {
+ exit_server_cleanly("construct_reply: srv_send_smb failed.");
+ }
+ TALLOC_FREE(req);
}
/****************************************************************************