小编rha*_*n33的帖子

UDP套接字集超时

我试图在UDP套接字上设置100ms超时.我正在使用C.我在下面发布了我的代码的相关部分.我不确定为什么这不是超时,但只是在它没有收到段时挂起.这仅适用于未使用bind()方法绑定的套接字吗?

#define TIMEOUT_MS      100     /* Seconds between retransmits */

if ((rcv_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    DieWithError("socket() failed");

if ((rcv_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    DieWithError("socket() failed");

//set timer for recv_socket
static int timeout = TIMEOUT_MS;
setsockopt(rcv_sock, SOL_SOCKET, SO_RCVTIMEO,(char*)&timeout,sizeof(timeout));

if(recvfrom(rcv_sock, ackBuffer,sizeof(ackBuffer), 0,
       (struct sockaddr *) &servAddr2, &fromSize) < 0){
    //timeout reached
    printf("Timout reached. Resending segment %d\n", seq_num);
    num_timeouts++;
}
Run Code Online (Sandbox Code Playgroud)

c sockets udp

30
推荐指数
2
解决办法
6万
查看次数

Errno:11,资源暂时不可用

我正在使用c套接字来实现可靠的UDP协议.我正在使用以下代码在我正在等待确认的套接字上设置超时.我不知道为什么我得到错误11,资源暂时不可用.

        //set timer for recv_socket
        struct timeval tv;
        tv.tv_usec = TIMEOUT_MS;

        if(setsockopt(rcv_sock, SOL_SOCKET, SO_RCVTIMEO,&tv,sizeof(tv)) < 0){
            printf("Error setting the socket timeout.\n");
        }

        int recv_msg_len;
        if(recv_msg_len = recvfrom(rcv_sock, ackBuffer,sizeof(ackBuffer), 0,
               (struct sockaddr *) &servAddr2, &fromSize) < 0){
            //timeout reached
            printf("Error Reporting: %d : %s\n", errno, strerror(errno));
            num_timeouts++;
        }
Run Code Online (Sandbox Code Playgroud)

我也尝试过评论中提到的select方法.我在循环中有以下代码,但recvfrom永远不会超时.

        fd_set set;
        FD_ZERO(&set);      /* empties the set */
        FD_CLR(rcv_sock,&set);    /* removes FD from the set */
        FD_SET(rcv_sock,&set);    /* adds FD to the set */

        if(select(rcv_sock + 1, &set, NULL, NULL, &tv) < …
Run Code Online (Sandbox Code Playgroud)

c sockets udp

14
推荐指数
1
解决办法
7万
查看次数

MSI参考计数:两个产品安装相同的MSI

当产品A和B各自安装多个MSI并且某些MSI相同时,卸载A或B会影响另一个吗?安装位置是否重要?

此外,当安装时产品B和B升级C中的常见MSI C版本较高时会发生什么?现在卸载B将删除打破产品A的常见MSI C.如何在不使用永久标志的情况下优雅地处理此问题?

installer windows-installer wix wix3 merge-module

8
推荐指数
1
解决办法
3923
查看次数

Java错误:无法从void转换为int []

我不明白为什么java认为数组"thisRow"在传递到Arrays.sort(thisRow)时是无效的."thisRow"对我来说似乎是一个int [].这是什么问题?

错误消息:"类型不匹配:无法在Test.mySort(Test.java:57)中从void转换为int []"

private static int[][] mySort(int[][] anArray) {
    for(int i = 0; i < anArray.length; i++){
        int thisRow[] = getRow(anArray, i);
        int[] sorted = Arrays.sort(thisRow);
    }
}

//This method will get the specified row out of the array.
private static int[] getRow(int[][] anArray, int row) {
    int thisRow[] = new int[anArray[row].length];
    for(int j = 0; j < anArray[row].length; j++){
        thisRow[j] = anArray[row][j];
    }
    return thisRow;
}
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1万
查看次数

如何强制Microsoft Azure .NET API调用失败?

我正在构建一个利用Microsoft Azure的应用程序,我正在使用Microsoft Azure .NET API调用来管理我的基础结构.我想进入测试阶段,我很好奇是否有办法强制调用失败其他提供虚假参数.

例如,我有以下代码片段可以启动VM.有没有办法让这个调用在给定正确的参数时自动失败?

using (ComputeManagementClient client = new ComputeManagementClient(new CertificateCloudCredentials(c_subscriptionId, MyCert)))
        {
            var status = client.VirtualMachines.Start(serviceName, deploymentName, vmName);
            if (status.Status == OperationStatus.Failed)
            {
                throw new MachineCreationException(status.Error.Code, null);
            }
        }
Run Code Online (Sandbox Code Playgroud)

提前致谢!

c# unit-testing azure azure-sdk-.net

0
推荐指数
1
解决办法
107
查看次数