Browse Source

ensure direct exit after calling back

any structures may be invalid after callback invocation.

this has the side effect that the socket write callback now returns
void, like all other callbacks do.
1.2
Oswald Buddenhagen 10 years ago
parent
commit
02af3f4c73
  1. 5
      src/drv_imap.c
  2. 5
      src/socket.c
  3. 4
      src/socket.h

5
src/drv_imap.c

@ -335,7 +335,7 @@ cmd_submittable( imap_store_t *ctx, struct imap_cmd *cmd )
ctx->num_in_progress < ((imap_store_conf_t *)ctx->gen.conf)->server->max_in_progress; ctx->num_in_progress < ((imap_store_conf_t *)ctx->gen.conf)->server->max_in_progress;
} }
static int static void
flush_imap_cmds( imap_store_t *ctx ) flush_imap_cmds( imap_store_t *ctx )
{ {
struct imap_cmd *cmd; struct imap_cmd *cmd;
@ -345,7 +345,6 @@ flush_imap_cmds( imap_store_t *ctx )
ctx->pending_append = &ctx->pending; ctx->pending_append = &ctx->pending;
send_imap_cmd( ctx, cmd ); send_imap_cmd( ctx, cmd );
} }
return 0;
} }
static void static void
@ -1589,7 +1588,7 @@ imap_open_store( store_conf_t *conf, const char *label,
socket_init( &ctx->conn, &srvc->sconf, socket_init( &ctx->conn, &srvc->sconf,
(void (*)( void * ))imap_invoke_bad_callback, (void (*)( void * ))imap_invoke_bad_callback,
imap_socket_read, (int (*)(void *))flush_imap_cmds, ctx ); imap_socket_read, (void (*)(void *))flush_imap_cmds, ctx );
socket_connect( &ctx->conn, imap_open_store_connected ); socket_connect( &ctx->conn, imap_open_store_connected );
} }

5
src/socket.c

@ -80,7 +80,7 @@ ssl_return( const char *func, conn_t *conn, int ret )
/* Callers take the short path out, so signal higher layers from here. */ /* Callers take the short path out, so signal higher layers from here. */
conn->state = SCK_EOF; conn->state = SCK_EOF;
conn->read_callback( conn->callback_aux ); conn->read_callback( conn->callback_aux );
return 0; return -1;
} }
sys_error( "Socket error: secure %s %s", func, conn->name ); sys_error( "Socket error: secure %s %s", func, conn->name );
} else { } else {
@ -766,7 +766,8 @@ do_queued_write( conn_t *conn )
conf_wakeup( &conn->ssl_fake, 0 ); conf_wakeup( &conn->ssl_fake, 0 );
#endif #endif
conn->writing = 0; conn->writing = 0;
return conn->write_callback( conn->callback_aux ); conn->write_callback( conn->callback_aux );
return -1;
} }
static void static void

4
src/socket.h

@ -88,7 +88,7 @@ typedef struct {
void (*bad_callback)( void *aux ); /* async fail while sending or listening */ void (*bad_callback)( void *aux ); /* async fail while sending or listening */
void (*read_callback)( void *aux ); /* data available for reading */ void (*read_callback)( void *aux ); /* data available for reading */
int (*write_callback)( void *aux ); /* all *queued* data was sent */ void (*write_callback)( void *aux ); /* all *queued* data was sent */
union { union {
void (*connect)( int ok, void *aux ); void (*connect)( int ok, void *aux );
void (*starttls)( int ok, void *aux ); void (*starttls)( int ok, void *aux );
@ -123,7 +123,7 @@ static INLINE void socket_init( conn_t *conn,
const server_conf_t *conf, const server_conf_t *conf,
void (*bad_callback)( void *aux ), void (*bad_callback)( void *aux ),
void (*read_callback)( void *aux ), void (*read_callback)( void *aux ),
int (*write_callback)( void *aux ), void (*write_callback)( void *aux ),
void *aux ) void *aux )
{ {
conn->conf = conf; conn->conf = conf;

Loading…
Cancel
Save