Thread: n00b doing a Socket operation on non-socket

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    n00b doing a Socket operation on non-socket

    ok this is a real sockets n00b question...

    My code...

    Code:
    if ( newFD = accept( scktFD, (struct sockaddr *)&client_addr, &sin_size ) == -1 ) {
    		perror( "connection_listen: accept" );
    		close( scktFD );
    		exit( EXIT_FAILURE );
    	}
    	
    	
    	
    	if (( send( newFD, "Hello world", 11, 0 )) == -1 ) {
    		perror( "send" );
    		close( newFD );
    		exit( EXIT_FAILURE );
    	}
    the send always fails and returns the error "Socket operation on non-socket", when i print newFD it is 0.

    I thought that was valid and i couldnt find a problem until i found this..
    [NOT TO FIX]
    60 * accept() returns a path name even if the connecting socket has closed
    61 * in the meantime (BSD loses the path and gives up).
    62 * accept() returns 0 length path for an unbound connector. BSD returns 16
    63 * and a null first byte in the path (but not for gethost/peername - BSD bug ??)
    in /net/unix/af_unix.c

    Anyway I have no idea what is going wrong or if I am using accept the wrong way. Any pointers would be great.
    "Assumptions are the mother of all **** ups!"

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Since fd 0 is usually stdin, sending to it is probably not a good idea.

    > newFD = accept( scktFD, (struct sockaddr *)&client_addr, &sin_size ) == -1
    Ah, good old precedence

    if ( a = b == c ) is like saying
    if ( a = ( b == c ) , call the func, compare with -1 and assign the boolean result to a

    You want
    if ( ( a = b ) == c ), call the func, assign to a and compare a with -1
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    wow salem, you did it again.. thanks
    "Assumptions are the mother of all **** ups!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  3. Replies: 5
    Last Post: 12-04-2008, 08:15 PM
  4. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM