Ver Fonte

FlowError: pass an int error code instead of a void *

ambrop7 há 15 anos atrás
pai
commit
d1e931fcb4

+ 4 - 6
client/DatagramPeerIO.c

@@ -40,7 +40,7 @@ static void init_sending (DatagramPeerIO *o, BAddr addr, BIPAddr local_addr);
 static void free_sending (DatagramPeerIO *o);
 static void init_receiving (DatagramPeerIO *o);
 static void free_receiving (DatagramPeerIO *o);
-static void error_handler (DatagramPeerIO *o, int component, const void *data);
+static void error_handler (DatagramPeerIO *o, int component, int code);
 static void reset_mode (DatagramPeerIO *o);
 static void recv_decoder_notifier_handler (DatagramPeerIO *o, uint8_t *data, int data_len);
 
@@ -80,16 +80,14 @@ void free_receiving (DatagramPeerIO *o)
     DatagramSocketSource_Free(&o->recv_source);
 }
 
-void error_handler (DatagramPeerIO *o, int component, const void *data)
+void error_handler (DatagramPeerIO *o, int component, int code)
 {
     ASSERT(o->mode == DATAGRAMPEERIO_MODE_CONNECT || o->mode == DATAGRAMPEERIO_MODE_BIND)
     DebugObject_Access(&o->d_obj);
     
-    int error = *((int *)data);
-    
     switch (component) {
         case DATAGRAMPEERIO_COMPONENT_SINK:
-            switch (error) {
+            switch (code) {
                 case DATAGRAMSOCKETSINK_ERROR_BSOCKET:
                     BLog(BLOG_NOTICE, "sink BSocket error %d", BSocket_GetError(&o->sock));
                     break;
@@ -101,7 +99,7 @@ void error_handler (DatagramPeerIO *o, int component, const void *data)
             }
             break;
         case DATAGRAMPEERIO_COMPONENT_SOURCE:
-            switch (error) {
+            switch (code) {
                 case DATAGRAMSOCKETSOURCE_ERROR_BSOCKET:
                     BLog(BLOG_NOTICE, "source BSocket error %d", BSocket_GetError(&o->sock));
                     break;

+ 1 - 1
client/PasswordSender.c

@@ -31,7 +31,7 @@ static void call_handler (PasswordSender *o, int is_error)
     DEBUGERROR(&o->d_err, o->handler(o->user, is_error))
 }
 
-static void error_handler (PasswordSender *o, int component, const void *data)
+static void error_handler (PasswordSender *o, int component, int code)
 {
     ASSERT(component == COMPONENT_SINK)
     DebugObject_Access(&o->d_obj);

+ 3 - 3
client/StreamPeerIO.c

@@ -65,7 +65,7 @@ static SECStatus client_client_auth_data_callback (StreamPeerIO *pio, PRFileDesc
 static void connecting_try_handshake (StreamPeerIO *pio);
 static void connecting_handshake_read_handler (StreamPeerIO *pio, PRInt16 event);
 static void connecting_pwsender_handler (StreamPeerIO *pio, int is_error);
-static void error_handler (StreamPeerIO *pio, int component, const void *data);
+static void error_handler (StreamPeerIO *pio, int component, int code);
 static void listener_handler_client (StreamPeerIO *pio, sslsocket *sock);
 static int init_io (StreamPeerIO *pio, sslsocket *sock);
 static void free_io (StreamPeerIO *pio);
@@ -309,7 +309,7 @@ fail0:
     return;
 }
 
-void error_handler (StreamPeerIO *pio, int component, const void *data)
+void error_handler (StreamPeerIO *pio, int component, int code)
 {
     ASSERT(pio->sock)
     DebugObject_Access(&pio->d_obj);
@@ -323,7 +323,7 @@ void error_handler (StreamPeerIO *pio, int component, const void *data)
             }
             break;
         case COMPONENT_DECODER:
-            BLog(BLOG_NOTICE, "decoder error %d", *((int *)data));
+            BLog(BLOG_NOTICE, "decoder error %d", code);
             break;
         default:
             ASSERT(0);

+ 1 - 1
dhcpclient/BDHCPClient.c

@@ -57,7 +57,7 @@ static const struct sock_filter dhcp_sock_filter[] = {
     BPF_STMT(BPF_RET + BPF_K, 0)                                  // ignore
 };
 
-static void error_handler (BDHCPClient *o, int component, const void *data)
+static void error_handler (BDHCPClient *o, int component, int code)
 {
     DebugObject_Access(&o->d_obj);
     

+ 1 - 1
flow/DatagramSocketSink.c

@@ -26,7 +26,7 @@
 
 static void report_error (DatagramSocketSink *s, int error)
 {
-    FlowErrorReporter_ReportError(&s->rep, &error);
+    FlowErrorReporter_ReportError(&s->rep, error);
     return;
 }
 

+ 1 - 1
flow/DatagramSocketSource.c

@@ -26,7 +26,7 @@
 
 static void report_error (DatagramSocketSource *s, int error)
 {
-    FlowErrorReporter_ReportError(&s->rep, &error);
+    FlowErrorReporter_ReportError(&s->rep, error);
     return;
 }
 

+ 2 - 2
flow/FlowError.c

@@ -36,7 +36,7 @@ FlowErrorReporter FlowErrorReporter_Create (FlowErrorDomain *domain, int compone
     return r;
 }
 
-void FlowErrorReporter_ReportError (FlowErrorReporter *reporter, const void *data)
+void FlowErrorReporter_ReportError (FlowErrorReporter *reporter, int code)
 {
-    reporter->domain->handler(reporter->domain->user, reporter->component, data);
+    reporter->domain->handler(reporter->domain->user, reporter->component, code);
 }

+ 4 - 4
flow/FlowError.h

@@ -35,9 +35,9 @@
  * @param user value specified to {@link FlowErrorDomain_Init}
  * @param component identifier of the component reporting the error, as in
  *                  {@link FlowErrorReporter_Create}
- * @param data component-specific error data, as in {@link FlowErrorReporter_ReportError}
+ * @param code component-specific error data, as in {@link FlowErrorReporter_ReportError}
  */ 
-typedef void (*FlowErrorDomain_handler) (void *user, int component, const void *data);
+typedef void (*FlowErrorDomain_handler) (void *user, int component, int code);
 
 /**
  * Object used to report errors from multiple sources to the same error handler.
@@ -78,8 +78,8 @@ FlowErrorReporter FlowErrorReporter_Create (FlowErrorDomain *domain, int compone
  *
  * @param reporter a {@link FlowErrorReporter} structure containing the error domain and
  *                 component identifier user to report the error
- * @param data component-specific error data
+ * @param code component-specific error data
  */
-void FlowErrorReporter_ReportError (FlowErrorReporter *reporter, const void *data);
+void FlowErrorReporter_ReportError (FlowErrorReporter *reporter, int code);
 
 #endif

+ 1 - 1
flow/PacketProtoDecoder.c

@@ -36,7 +36,7 @@ static void output_handler_done (PacketProtoDecoder *enc);
 
 void report_error (PacketProtoDecoder *enc, int error)
 {
-    FlowErrorReporter_ReportError(&enc->rep, &error);
+    FlowErrorReporter_ReportError(&enc->rep, error);
     return;
 }
 

+ 1 - 1
flow/StreamSocketSink.c

@@ -26,7 +26,7 @@
 
 static void report_error (StreamSocketSink *s, int error)
 {
-    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, &error))
+    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, error))
 }
 
 static void try_send (StreamSocketSink *s)

+ 1 - 1
flow/StreamSocketSource.c

@@ -26,7 +26,7 @@
 
 static void report_error (StreamSocketSource *s, int error)
 {
-    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, &error))
+    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, error))
 }
 
 static void try_recv (StreamSocketSource *s)

+ 1 - 1
ipc/BIPC.c

@@ -26,7 +26,7 @@
 #define COMPONENT_SINK 2
 #define COMPONENT_DECODER 3
 
-static void error_handler (BIPC *o, int component, const void *data)
+static void error_handler (BIPC *o, int component, int code)
 {
     DebugObject_Access(&o->d_obj);
     

+ 1 - 1
nspr_support/PRStreamSink.c

@@ -28,7 +28,7 @@
 
 static void report_error (PRStreamSink *s, int error)
 {
-    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, &error))
+    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, error))
 }
 
 static void try_send (PRStreamSink *s)

+ 1 - 1
nspr_support/PRStreamSource.c

@@ -28,7 +28,7 @@
 
 static void report_error (PRStreamSource *s, int error)
 {
-    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, &error))
+    DEBUGERROR(&s->d_err, FlowErrorReporter_ReportError(&s->rep, error))
 }
 
 static void try_recv (PRStreamSource *s)

+ 3 - 3
server/server.c

@@ -219,7 +219,7 @@ static int client_init_io (struct client_data *client);
 static void client_dealloc_io (struct client_data *client);
 
 // handler for client I/O errors. Removes the client.
-static void client_error_handler (struct client_data *client, int component, const void *data);
+static void client_error_handler (struct client_data *client, int component, int code);
 
 // provides a buffer for sending a control packet to the client
 static int client_start_control_packet (struct client_data *client, void **data, int len);
@@ -1306,7 +1306,7 @@ void client_dealloc_io (struct client_data *client)
     }
 }
 
-void client_error_handler (struct client_data *client, int component, const void *data)
+void client_error_handler (struct client_data *client, int component, int code)
 {
     ASSERT(INITSTATUS_HASLINK(client->initstatus))
     ASSERT(!client->dying)
@@ -1320,7 +1320,7 @@ void client_error_handler (struct client_data *client, int component, const void
             }
             break;
         case COMPONENT_DECODER:
-            client_log(client, BLOG_NOTICE, "decoder error %d", *((int *)data));
+            client_log(client, BLOG_NOTICE, "decoder error %d", code);
             break;
         default:
             ASSERT(0);

+ 3 - 3
server_connection/ServerConnection.c

@@ -41,7 +41,7 @@ static void report_error (ServerConnection *o);
 static void connect_handler (ServerConnection *o, int event);
 static void pending_handler (ServerConnection *o);
 static SECStatus client_auth_data_callback (ServerConnection *o, PRFileDesc *fd, CERTDistNames *caNames, CERTCertificate **pRetCert, SECKEYPrivateKey **pRetKey);
-static void error_handler (ServerConnection *o, int component, const void *data);
+static void error_handler (ServerConnection *o, int component, int code);
 static void input_handler_send (ServerConnection *o, uint8_t *data, int data_len);
 static void packet_hello (ServerConnection *o, uint8_t *data, int data_len);
 static void packet_newclient (ServerConnection *o, uint8_t *data, int data_len);
@@ -261,7 +261,7 @@ SECStatus client_auth_data_callback (ServerConnection *o, PRFileDesc *fd, CERTDi
     return SECSuccess;
 }
 
-void error_handler (ServerConnection *o, int component, const void *data)
+void error_handler (ServerConnection *o, int component, int code)
 {
     ASSERT(o->state >= STATE_WAITINIT)
     DebugObject_Access(&o->d_obj);
@@ -275,7 +275,7 @@ void error_handler (ServerConnection *o, int component, const void *data)
             }
             break;
         case COMPONENT_DECODER:
-            BLog(BLOG_ERROR, "decoder error %d", *((int *)data));
+            BLog(BLOG_ERROR, "decoder error %d", code);
             break;
         default:
             ASSERT(0);

+ 3 - 3
socksclient/BSocksClient.c

@@ -45,7 +45,7 @@ static void init_up_io (BSocksClient *o);
 static void free_up_io (BSocksClient *o);
 static void start_receive (BSocksClient *o, uint8_t *dest, int total);
 static void do_receive (BSocksClient *o);
-static void error_handler (BSocksClient *o, int component, const void *data);
+static void error_handler (BSocksClient *o, int component, int code);
 static void socket_error_handler (BSocksClient *o, int event);
 static void connect_handler (BSocksClient *o, int event);
 static void recv_handler_done (BSocksClient *o, int data_len);
@@ -116,12 +116,12 @@ void do_receive (BSocksClient *o)
     StreamRecvInterface_Receiver_Recv(o->control.recv_if, o->control.recv_dest + o->control.recv_len, o->control.recv_total - o->control.recv_len);
 }
 
-void error_handler (BSocksClient *o, int component, const void *data)
+void error_handler (BSocksClient* o, int component, int code)
 {
     ASSERT(component == COMPONENT_SOURCE || component == COMPONENT_SINK)
     DebugObject_Access(&o->d_obj);
     
-    if (o->state == STATE_UP && component == COMPONENT_SOURCE && *((int *)data) == STREAMSOCKETSOURCE_ERROR_CLOSED) {
+    if (o->state == STATE_UP && component == COMPONENT_SOURCE && code == STREAMSOCKETSOURCE_ERROR_CLOSED) {
         BLog(BLOG_DEBUG, "connection closed");
         
         report_error(o, BSOCKSCLIENT_EVENT_ERROR_CLOSED);