我在Linux工具箱中遇到glib2.56.1-2的问题。我找到了一个简单的TCP服务器示例:
int main (int argc, char *argv[])
{
GError * error = NULL;
/* create the new socketservice */
GSocketService* service = g_socket_service_new ();
/* connect to the port */
struct sockaddr_in serv_addr;
memset(&serv_addr, 0x0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(8000);
g_socket_listener_add_address ((GSocketListener*)service,
g_socket_address_new_from_native(&serv_addr, sizeof(serv_addr)),
G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_TCP,
NULL,
NULL,
&error);
/* listen to the 'incoming' signal */
g_signal_connect (service,
"incoming",
G_CALLBACK (incoming_callback),
NULL);
/* start the socket service */
g_socket_service_start (service);
/* enter mainloop */
g_print ("Waiting for client!\n");
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
return 0;
}
但这给了我以下警告:
(process:9633862): GLib-GObject-WARNING **: 12:48:11.025: gsignal.c:2523: signal 'incoming' is invalid for instance '110015730' of type 'GSocketService'
连接似乎已打开,但是由于您在上面看到的信号警告,因此无法处理传入的数据。你有什么主意吗?
Jiri。
答案 0 :(得分:0)
我从链接器标志中删除了-Wl,-G。很好。谢谢大家。