简体   繁体   中英

nvidia drivers make socket fail on accept

Here is a compiling extract of a program that uses glut and pthreads.

With nvidia driver version 295 the tcp accept interrupted when glutmainloop starts (the program reports error 4)

with version 275 the program works fine.

(ubuntu, 3.0.0-17-generic #30-Ubuntu SMP Thu Mar 8 20:45:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux problem verified also with 3.0.0-16)

Including -lglut and -lpthread in either order does not fix the problem if the glStuff function is not called, the program works as expected

did someone encounter similar problems?

#include <GL/glut.h>  
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <iostream>

using namespace std;


enum Error{WSASTARTUP,SOCKETCREATION,SOCKETBINDING,SOCKETLISTENING,SOCKETACCEPT};
void onError(Error err){
 std::cerr<<"error"<<err<<endl;
}


void* serverrun(void*){
 int mainSocket;
 int port=15002;
 struct sockaddr_in local;
 local.sin_family=AF_INET;
 local.sin_addr.s_addr=htonl(INADDR_ANY);
 local.sin_port=htons((u_short)port);
 mainSocket=socket(AF_INET,SOCK_STREAM,0);
 int val=1;
 setsockopt(mainSocket,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val));
 if(mainSocket<0){
  onError(SOCKETCREATION);  
}
if(bind(mainSocket, (struct sockaddr*)&local,sizeof(local))!=0)
{
  onError(SOCKETBINDING);
}
if(listen(mainSocket,10)!=0)
{
  onError(SOCKETLISTENING);
} 
struct sockaddr_in from;
socklen_t fromlen=sizeof(from);

while(true){
 int cs;
 cs=accept(mainSocket,(struct sockaddr*)&from,&fromlen);
 if (cs!=-1){
  std::cout<<"new client"<<std::endl;
 }else{
   onError(SOCKETACCEPT);
 }
}//while running
return NULL;
}//run

void drawGLScene(){}

void idleFunc(){}



void glStuff(int& argc,char** argv){
 glutInit(&argc, argv);  
 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);    
 glutInitWindowSize(100,100);  
 glutInitWindowPosition(0,0);
 glutCreateWindow("win");
 glutDisplayFunc(drawGLScene);      
 glutIdleFunc(idleFunc);
 glutMainLoop();
}

You seem to be completely ignoring errno , what is the exact error that you see?

If it is EINTR , you should just retry, that's perfectly normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM