简体   繁体   English

send(),返回Winsock错误10038

[英]send(), returns Winsock Error 10038

Problem: 问题:

  • Call to send() , returns Winsock Error 10038 against socket handle 调用send() ,针对套接字句柄返回Winsock错误10038

Illustration: 插图:

acceptedSocket = accept (server, (sockaddr *)&sin, &len);
  • accept() , returns 0 accept() ,返回0
    • A new thread , is created for each connection 为每个连接创建一个新线程
    • send() , (in thread function) returns 10038 send() ,(在线程函数中)返回10038

Illustration: - in thread function 插图: -螺纹功能

//omitted
SOCKET RemoteSocket = (SOCKET) client;
//omitted
send (RemoteSocket, stringToSpend, strlen(stringToSpend), 0)

Suggestions: 建议:

  • Possible, race condition? 可能,比赛条件?
  • Could use I/O completion ports, but not at this stage 可以使用I / O完成端口,但目前不能使用

accept() returns you a handle to a new connection-specific socket. accept()返回一个新的特定于连接的套接字的句柄。 for server code it's 2+ sockets involved: one is in listen state you are calling accept() for and second is one returned from accept() - it's an incoming connection socket. 对于服务器代码,它涉及2个以上的套接字:一个处于侦听状态,您正在为其调用accept(),第二个是从accept()返回的一个-这是一个传入的连接套接字。 Following accept() can return socket for second incoming connection etc. if accept() returns 0 it's not an incoming connection - it's an error. 跟随accept()可以为第二次传入连接返回套接字,等等。如果accept()返回0,则它不是传入连接-这是一个错误。

Isn't the problem in the line 这不是问题所在吗

acceptedSocket = accept (server, (sockaddr *)&sin, &len) == INVALID_SOCKET)

You make acceptedSocket the result of the comparison, but you should store the actual socket returned from accept somehow: 您使acceptedSocket作为比较的结果,但是您应该以某种方式存储从accept返回的实际套接字:

acceptedSocket = accept (server, (sockaddr *)&sin, &len);
isOK= acceptedSocket!=INVALID_SOCKET;

Although I'm a bit confused by the unbalanced parentheses in your post, so I may be wrong 尽管我对您的帖子中括号不平衡有些困惑,所以我可能是错的

Hmm, seems like your send is executing too fast before the accept happened. 嗯,好像您的sendaccept发生之前执行得太快了。 So the socket used in send is not valid at the point send is executed. 因此,在执行send时,send中使用的套接字无效。 One of the obnoxious feature of multithreading. 多线程的令人讨厌的功能之一。 You need to wait for an event at the send thread and fire an event when an accept occurs 您需要在send线程上等待事件,并在接受时触发事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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