【问题标题】:Probable reasons for Illegal seek in socket programming [closed]套接字编程中非法搜索的可能原因[关闭]
【发布时间】:2015-08-09 07:44:53
【问题描述】:

我在发送数据时收到以下错误。

send:29-非法搜索

请解释可能的原因。我是套接字编程的新手。提前致谢。

CHAR datasend[200];
    DOUBLE64 fTime=0.0;
    LONG32 sent_bytes=0;
    while(TRUE)
    {
            memset(datasend,0,200);
            fTime=getTime();
            sprintf(datasend,"0=%.0lf ",fTime);
            sent_bytes = send ( isockfd, datasend, strlen(datasend),0);
            logDebug1("Pulse is %s and data bytes is %d",datasend,strlen(datasend));
            if(sent_bytes <= 0)
            {
                    logPError("send");
                    logTimestamp("Closing socket\n");
                    close(isockfd);
                    return NULL;
            }

            sleep(25);

    }

【问题讨论】:

  • 你忘记贴相关源码了。
  • 你去。我已经编辑并添加了源代码
  • @user1095108 : 你能详细说明一下
  • 删除logDebug1,再检查
  • @user2531564 没关系,你对 errno 的解释是错误的。

标签: c++ c sockets


【解决方案1】:

由于logDebug1 调用介入,您没有解释正确的错误

  • 您有一个 send 返回一些 errno
  • 你打印了一些东西 (logDebug1)这可能会破坏 errno
  • 你做了某种perror 来解释被破坏的errno

您想要做的是立即检查sentBytes &lt; 0perror,然后可能会打印更多调试内容。

【讨论】:

  • logDebug1 和 logPError 和 logTimestamp 是使用 printf 和 perror 函数打印数据的函数。我对更广泛的图片的查询是,出现非法搜索错误的可能原因是什么。
  • @user2531564:如果你不反思他写的东西,我们怎么知道你是否理解了它?
  • @user2531564 “更广泛的情况”是您没有从套接字操作中获得“非法搜索”错误。你得到一个目前未知的错误,你在获取它和打印它之间做了其他事情而破坏了它。请注意。
猜你喜欢
  • 2011-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-10
相关资源
最近更新 更多