@@ -40,11 +40,11 @@ static void on_recv(int fd, void *arg)
4040 struct sock_server * s = (struct sock_server * )arg ;
4141 ret = sock_recv (fd , buf , 2048 );
4242 if (ret > 0 ) {
43- s -> on_buffer (fd , buf , ret );
43+ s -> on_buffer (s , buf , ret );
4444 } else if (ret == 0 ) {
4545 printf ("delete connection fd:%d\n" , fd );
4646 if (s -> on_disconnect ) {
47- s -> on_disconnect (fd , NULL );
47+ s -> on_disconnect (s , NULL );
4848 }
4949 } else if (ret < 0 ) {
5050 printf ("%s:%d recv failed!\n" , __func__ , __LINE__ );
@@ -59,11 +59,11 @@ static void on_client_recv(int fd, void *arg)
5959 struct sock_client * c = (struct sock_client * )arg ;
6060 ret = sock_recv (fd , buf , 2048 );
6161 if (ret > 0 ) {
62- c -> on_buffer (fd , buf , ret );
62+ c -> on_buffer (c , buf , ret );
6363 } else if (ret == 0 ) {
6464 printf ("delete connection fd:%d\n" , fd );
6565 if (c -> on_disconnect ) {
66- c -> on_disconnect (fd , NULL );
66+ c -> on_disconnect (c , NULL );
6767 }
6868 } else if (ret < 0 ) {
6969 printf ("%s:%d recv failed!\n" , __func__ , __LINE__ );
@@ -114,7 +114,7 @@ static void on_tcp_connect(int fd, void *arg)
114114 sc .remote .ip = ip ;
115115 sc .remote .port = port ;
116116 sock_addr_ntop (sc .remote .ip_str , ip );
117- s -> on_connect (fd , & sc );
117+ s -> on_connect (s , & sc );
118118 }
119119 e = gevent_create (afd , on_recv , NULL , on_error , s );
120120 if (-1 == gevent_add (s -> evbase , & e )) {
@@ -195,9 +195,9 @@ struct sock_server *sock_server_create(const char *host, uint16_t port, enum soc
195195}
196196
197197int sock_server_set_callback (struct sock_server * s ,
198- void (* on_connect )(int fd , struct sock_connection * conn ),
199- void (* on_buffer )(int , void * buf , size_t len ),
200- void (* on_disconnect )(int fd , struct sock_connection * conn ))
198+ void (* on_connect )(struct sock_server * s , struct sock_connection * conn ),
199+ void (* on_buffer )(struct sock_server * s , void * buf , size_t len ),
200+ void (* on_disconnect )(struct sock_server * s , struct sock_connection * conn ))
201201{
202202 struct gevent * e ;
203203 if (!s ) {
@@ -274,9 +274,9 @@ struct sock_client *sock_client_create(const char *host, uint16_t port, enum soc
274274}
275275
276276int sock_client_set_callback (struct sock_client * c ,
277- void (* on_connect )(int fd , struct sock_connection * conn ),
278- void (* on_buffer )(int , void * buf , size_t len ),
279- void (* on_disconnect )(int fd , struct sock_connection * conn ))
277+ void (* on_connect )(struct sock_client * c , struct sock_connection * conn ),
278+ void (* on_buffer )(struct sock_client * c , void * buf , size_t len ),
279+ void (* on_disconnect )(struct sock_client * c , struct sock_connection * conn ))
280280{
281281 if (!c ) {
282282 return -1 ;
@@ -324,7 +324,7 @@ GEAR_API int sock_client_connect(struct sock_client *c)
324324 }
325325 if (c -> conn ) {
326326 if (c -> on_connect ) {
327- c -> on_connect (c -> conn -> fd , c -> conn );
327+ c -> on_connect (c , c -> conn );
328328 }
329329 }
330330 c -> thread = thread_create (sock_client_thread , c );
0 commit comments