伙计们,这里ma代码:
#include #include // gio channel #include //socket(); #include // structure #include // printf void deal(GIOChannel *in, GIOCondition condition, gpointer data) { struct sockaddr_storage income; int insock = g_io_channel_unix_get_fd(in); socklen_t income_len = sizeof(income); int newsock = accept(insock, (struct sockaddr*)&income, &income_len ); if(newsock == -1) { printf("failure on newsockn"); } char buff[128]; int recv_total = 0; int recv_byte = 128; int recv_sizing; while (recv_total < recv_byte ){ recv_sizing = recv(newsock,buff + recv_total,recv_byte,0); // breaking if recv_sizing = -1 assuming as error, 0 assuming as lost communication from client suddenly if(recv_sizing < 0 || recv_sizing == 0) { printf("connection lost or error while recv(); [ just guess ] number : %d n",recv_sizing); break; } recv_byte -= recv_sizing; recv_total += recv_sizing; } buff[recv_total] = '