当前位置: 技术问答>linux和unix
Program received signal SIGSEGV, Segmentation fault,求帮助~
来源: 互联网 发布时间:2017-01-23
本文导语: void *sock_read(int client) { ······ } static void sock_accept(int server_socket,short event,void *arg)//char **argv { printf("start sock_acceptn"); struct event *ev=arg; int new_server_socket; //////////////////////////////////////// ///////////////////////...
void *sock_read(int client)
{
······
}
static void sock_accept(int server_socket,short event,void *arg)//char **argv
{
printf("start sock_acceptn");
struct event *ev=arg;
int new_server_socket;
////////////////////////////////////////
/////////////////////////////////
printf("start acceptn");
while(1) //服务器端要一直运行,
{
////////////////////////////////
/////////////////////////////////
struct sockaddr addr;
socklen_t len=sizeof(addr);
//由于此结构要长期使用,所以rev必须动态分配,否则离开此函数后会自动释放,导致segment fault
struct event *rev=(struct event *)malloc(sizeof(struct event));//*rev
new_server_socket=accept(server_socket,&addr,&len);
if(new_server_socket==-1)
{
fprintf(stderr,"Sock Accept Failed!n");
return;
}
fprintf(stdout,"accept socket:%dn",new_server_socket);
////////////////////////////////
///////////////////////////////
pthread_t child_thread;
pthread_mutex_init(&mutex,NULL);//初始化
printf("start talk to sock_readn");
if((pthread_create(&child_thread,NULL,sock_read(new_server_socket),NULL))