Solaris 2.3 Non-blocking woes

Solaris 2.3 Non-blocking woes

Post by Mahesh Neelakan » Sun, 06 Nov 1994 10:43:01



Here's a good one:
   I am trying to use setsockopt and/or getsockopt on a _non-blocking_ AF_INET
socket under Solaris 2.3. Unfortunately, for some reason, if I give it an
destination IP address (or a destination address that is real far away),
solaris just hangs/blocks on the call! I've tried the same code
on a BSD/386 1.1 machine and a RS/6000 and both return right back from
[sg]etsockopt with a EINPROGRESS (i.e. connection is still being established).

Also, under SunOS 4.1, I can't seem to do the FIONBIO on the socket..it says
Operation not permitted on socket...is there some other method for SunOS?

The code below takes two arguments, your local IP and the destination IP
(ex: ./socktest 199.227.15.16 199.227.15.2). Under solaris, the code will
block on the sockopt functions.

I've applied the OS patches from sunsolve.sun.com to my sparc and one of those
patches mentioned blocking on reads on non-blocking sockets but to no avail.
Any help/input greatly appreciated!

TIA,

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <sys/filio.h> /* Only for Solaris and SunOS */
#include <sys/ioctl.h>

int
main(
int argc,
char *argv[])
{
     int sockfd;
     int nonblk;
     int winsiz;
     int len;
     struct sockaddr_in myaddr;
     struct sockaddr_in rhaddr;

     if (argc < 3) {
          exit(1);
     }
     if ((sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0) {
          perror("socket");
          exit(errno);
     }

     nonblk=1;
     if (ioctl(sockfd,FIONBIO,&nonblk) < 0) {
          perror("ioctl");
          exit(errno);
     }

     memset(&myaddr,0,sizeof(myaddr));
     memset(&rhaddr,0,sizeof(rhaddr));

     myaddr.sin_family=AF_INET;
     myaddr.sin_addr.s_addr=inet_addr(argv[1]);
     myaddr.sin_port=htons(0);
     if (bind(sockfd,(struct sockaddr *)&myaddr,sizeof(myaddr)) < 0) {
          perror("bind");
          exit(errno);
     }

     rhaddr.sin_family=AF_INET;
     rhaddr.sin_addr.s_addr=inet_addr(argv[2]);
     rhaddr.sin_port=ntohs(23);
     if (connect(sockfd,(struct sockaddr *)&rhaddr,sizeof(rhaddr)) < 0) {
          perror("connect");
          if (errno != EINPROGRESS) {
               close(sockfd);
               exit(errno);
          }
     }

     len=sizeof(winsiz);
     fprintf(stderr,"Getting buffer sizes.\n");
     if (getsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,(char*)winsiz,&len) < 0) {
          perror("getsockopt");
     }
     if (errno) {
          perror("getsockopt");
     }
     fprintf(stderr,"Send buffer size=%d\n",winsiz);
     if (getsockopt(sockfd,SOL_SOCKET,SO_RCVBUF,(char*)winsiz,&len) < 0) {
          perror("getsockopt");
     }
     if (errno) {
          perror("getsockopt");
     }
     fprintf(stderr,"Recv buffer size=%d\n",winsiz);
     close(sockfd);

Quote:}

 
 
 

1. HELP: non-blocking read Solaris 2.3 /dev/bpp0

On Solaris 2.3 with Sparc 10:

Can someone please suggest a sensible way to check if characters are
waiting to be read from an I/O channel?

I would like to be able to do an fopen on /dev/bpp0 (the parallel port)
and see if there are any characters waiting to be read.  Or some kind of
non-blocking read would be OK also.  What is the technique required
under Solaris 2.x?

2. SMC EtherPower Installation?

3. solaris 2.3 non blocking sockets issues

4. mouse cursor jump when CPU busy

5. Blocking connect() fails, non-blocking succeeds?

6. new 2.5.72 breaks aumix

7. Blocking and Non-Blocking socket

8. Error compiling Libvga-1.2.9

9. [2.2] pipe_write can block even with non-blocking fd

10. how to get blocking i/o after non-blocking???

11. [2.5] Non-blocking write can block

12. Blocking & Non-Blocking

13. Non-blocking socket reads block! (Bug?)