0

I have a code something like this.

where recvfrom works fine if i run the code normally. but when i run the code with GDB, recvfrom doesn't wait for 2 seconds and instantly throwing errno 14.

==

char buf[sizeof(FSME_START)] = { 0 };

/* open socket */
fsm_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fsm_fd < 0)
{
    perror("socket");
    exit(1);
}

const struct sockaddr_in remote_addr = { .sin_family = AF_INET };
//socklen_t addrlen = sizeof(struct sockaddr);
socklen_t addrlen = sizeof(client_addr);

struct timeval tv = { .tv_sec = 2,
                      .tv_usec = 0};

/* set initial 1s recv timeout */
int ret = setsockopt(fsm_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
if (ret < 0)
{
    perror("setsockopt");
    exit(1);
}

while (1)
{
    const struct iovec iov = { .iov_base = (void*)FSME_START,
                               .iov_len = sizeof(FSME_START) };

    // Send the START packet (once/sec) to the FSM-E until we get
    // receive a START message back based on 1sec timeout set above.
    fsm_dp_send(&iov,1,0);
    ret = recvfrom(fsm_fd, (char *)buf, MAX_BUFSIZE,
                MSG_WAITALL, (struct sockaddr *)&client_addr, &addrlen);

==== I tried passing client_addr and addrlen both parameters as NULL but no success. But strangely this code works if run without GDB.

Any suggestions

pgoyal
  • 91
  • 1
  • 3

1 Answers1

0

looks like there is an error with the size of msg i was passing with recvfrom but it was weird that one version of gdb and and even compiler was hiding this error. This error was visible only with older gdb version. Later on when i passed the correct size of the buffer, it was passing.

pgoyal
  • 91
  • 1
  • 3