Ejemplo n.º 1
0
static void
process_the_patch (client_t *self, server_t *server)
{
    char *inbox = fmq_config_resolve (self->config, "client/inbox", ".inbox");        
    char *filename = fmq_msg_filename (server->reply);                                
                                                                                      
    //  Filenames from server must start with slash, which we skip                    
    assert (*filename == '/');                                                        
    filename++;                                                                       
                                                                                      
    if (fmq_msg_operation (server->reply) == FMQ_MSG_FILE_CREATE) {                   
        if (server->file == NULL) {                                                   
            server->file = fmq_file_new (inbox, filename);                            
            if (fmq_file_output (server->file)) {                                     
                //  File not writeable, skip patch                                    
                fmq_file_destroy (&server->file);                                     
                return;                                                               
            }                                                                         
        }                                                                             
        //  Try to write, ignore errors in this version                               
        zframe_t *frame = fmq_msg_chunk (server->reply);                              
        fmq_chunk_t *chunk = fmq_chunk_new (zframe_data (frame), zframe_size (frame));
        if (fmq_chunk_size (chunk) > 0) {                                             
            fmq_file_write (server->file, chunk, fmq_msg_offset (server->reply));     
            server->credit -= fmq_chunk_size (chunk);                                 
        }                                                                             
        else {                                                                        
            //  Zero-sized chunk means end of file, so report back to caller          
            zstr_sendm (self->pipe, "DELIVER");                                       
            zstr_sendm (self->pipe, filename);                                        
            zstr_sendf (self->pipe, "%s/%s", inbox, filename);                        
            fmq_file_destroy (&server->file);                                         
        }                                                                             
        fmq_chunk_destroy (&chunk);                                                   
    }                                                                                 
    else                                                                              
    if (fmq_msg_operation (server->reply) == FMQ_MSG_FILE_DELETE) {                   
        zclock_log ("I: delete %s/%s", inbox, filename);                              
        fmq_file_t *file = fmq_file_new (inbox, filename);                            
        fmq_file_remove (file);                                                       
        fmq_file_destroy (&file);                                                     
    }                                                                                 
}
Ejemplo n.º 2
0
static void
process_the_patch (client_t *self)
{
    char *inbox = fmq_config_resolve (self->config, "client/inbox", ".inbox");        
    char *filename = fmq_msg_filename (self->reply);                                  
                                                                                      
    if (fmq_msg_operation (self->reply) == FMQ_MSG_FILE_CREATE) {                     
        if (self->file == NULL) {                                                     
            zclock_log ("I: create %s", filename);                                    
            self->file = fmq_file_new (inbox, filename);                              
            if (fmq_file_output (self->file)) {                                       
                //  File not writeable, skip patch                                    
                fmq_file_destroy (&self->file);                                       
                return;                                                               
            }                                                                         
        }                                                                             
        //  Try to write, ignore errors in this version                               
        zframe_t *frame = fmq_msg_chunk (self->reply);                                
        fmq_chunk_t *chunk = fmq_chunk_new (zframe_data (frame), zframe_size (frame));
        if (fmq_chunk_size (chunk) > 0) {                                             
            fmq_file_write (self->file, chunk, fmq_msg_offset (self->reply));         
            self->credit -= fmq_chunk_size (chunk);                                   
        }                                                                             
        else                                                                          
            //  Zero-sized chunk means end of file                                    
            fmq_file_destroy (&self->file);                                           
        fmq_chunk_destroy (&chunk);                                                   
    }                                                                                 
    else                                                                              
    if (fmq_msg_operation (self->reply) == FMQ_MSG_FILE_DELETE) {                     
        zclock_log ("I: delete %s", filename);                                        
        fmq_file_t *file = fmq_file_new (inbox, filename);                            
        fmq_file_remove (file);                                                       
        fmq_file_destroy (&file);                                                     
    }                                                                                 
}