0

What is the difference between Non blocking and Asynchronous socket modes that we set using below calls.

  1. Case 1: int sockfd; // create_sock(sockfd);

    // init_sock(sockfd);

    fcntl(sockfd, F_SETFL, O_NONBLOCK);

  2. Case 2:

    int sockfd; // create_sock(sockfd);

    // init_sock(sockfd);

    int on = 1;

    ioctl(sockfd, FIOASYNC, &on);

  3. Case 3:

    int sockfd;

    // create_sock(sockfd);

    // init_sock(sockfd);

    int on = 1; ioctl(sockfd, FIONBIO, &on)

What will be the behavior of the socket in all the above cases.

Thanks,

akure
  • 49
  • 1
  • 7

1 Answers1

1

'Non-blocking' means that the function either did or didn't do something, and returned a status that told you which.

'Asynchronous' means that the operation invoked by the function keeps running after the function returns, and it notifies you of its completion or failure by other means, e.g. a callback or a handle you can interrogate for status.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • thanks, could you also explain the behavior of sockets in the three cases that I mention in question. – akure May 07 '14 at 12:47
  • Cases 1 and 3 are non-blocking, which is what both `O_NONBLOCK` and `FIONBIO` mean, case 2 is asynchronous, which is what `FIOASYNC` means. I don't think you really needed me to tell you that. – user207421 May 08 '14 at 00:29