r4757: added the ability of the clisocket level of libcli to handle async
[jelmer/samba4-debian.git] / source / ntvfs / cifs / vfs_cifs.c
index 9e3c841dd36ab3f78303fb96bb1cb390a740daa8..1a5a5ac042a95cf358bc01eddcd5ca2df85dbe82 100644 (file)
@@ -26,6 +26,7 @@
 */
 
 #include "includes.h"
+#include "events.h"
 #include "libcli/raw/libcliraw.h"
 #include "smb_server/smb_server.h"
 
@@ -77,7 +78,8 @@ static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uin
  /*
   a handler for read events on a connection to a backend server
 */
-static void cifs_socket_handler(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags)
+static void cifs_socket_handler(struct event_context *ev, struct fd_event *fde, 
+                               struct timeval t, uint16_t flags)
 {
        struct cvfs_private *private = fde->private;
        struct smbsrv_tcon *tcon = private->tcon;
@@ -86,7 +88,7 @@ static void cifs_socket_handler(struct event_context *ev, struct fd_event *fde,
        
        if (!smbcli_transport_process(private->transport)) {
                /* the connection to our server is dead */
-               close_cnum(tcon);
+               talloc_free(tcon);
        }
 }
 
@@ -119,7 +121,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_INVALID_PARAMETER;
        }
        
-       private = talloc(req->tcon, sizeof(struct cvfs_private));
+       private = talloc_p(req->tcon, struct cvfs_private);
        if (!private) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -148,14 +150,14 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        
        /* we need to receive oplock break requests from the server */
        smbcli_oplock_handler(private->transport, oplock_handler, private);
-       smbcli_transport_idle_handler(private->transport, idle_func, 1, private);
+       smbcli_transport_idle_handler(private->transport, idle_func, 50000, private);
 
-       private->transport->event.fde->handler = cifs_socket_handler;
-       private->transport->event.fde->private = private;
+       private->transport->socket->event.fde->handler = cifs_socket_handler;
+       private->transport->socket->event.fde->private = private;
 
-       private->transport->event.ctx = event_context_merge(tcon->smb_conn->connection->event.ctx,
-                                                           private->transport->event.ctx);
-       talloc_reference(private, private->transport->event.ctx);
+       private->transport->socket->event.ctx = event_context_merge(tcon->smb_conn->connection->event.ctx,
+                                                                   private->transport->socket->event.ctx);
+       talloc_reference(private, private->transport->socket->event.ctx);
        private->map_generic = lp_parm_bool(req->tcon->service, 
                                            "cifs", "mapgeneric", False);
 
@@ -648,6 +650,15 @@ static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
        return NT_STATUS_OK;
 }
 
+/*
+  cancel an async call
+*/
+static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs, 
+                           struct smbsrv_request *req)
+{
+       return NT_STATUS_NOT_IMPLEMENTED;
+}
+
 /*
   lock a byte range
 */
@@ -853,6 +864,7 @@ NTSTATUS ntvfs_cifs_init(void)
        ops.trans = cvfs_trans;
        ops.logoff = cvfs_logoff;
        ops.async_setup = cvfs_async_setup;
+       ops.cancel = cvfs_cancel;
 
        if (lp_parm_bool(-1, "cifs", "maptrans2", False)) {
                ops.trans2 = cvfs_trans2;
@@ -860,7 +872,7 @@ NTSTATUS ntvfs_cifs_init(void)
 
        /* register ourselves with the NTVFS subsystem. We register
           under the name 'cifs'. */
-       ret = register_backend("ntvfs", &ops);
+       ret = ntvfs_register(&ops);
 
        if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(0,("Failed to register CIFS backend!\n"));