• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: SO_NOSIGPIPE option.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SO_NOSIGPIPE option.


  • Subject: Re: SO_NOSIGPIPE option.
  • From: Vincent Lubet <email@hidden>
  • Date: Wed, 7 Oct 2009 14:43:41 -0700

Robert,

This is indeed a bug of Mac OS X 10.5.x where a number of socket options are not inherited from the listening socket.

The workaround is to call setsockopt(SO_NOSIGPIPE) just after accept() return the socket for the new connection. Because of the other problem mentioned by Glenn Anderson your code should be ready for setsockopt() to fail with EINVAL if the peer has already closed the connection.

Vincent

On Oct 7, 2009, at 1:55 PM, Robert Bell wrote:


The client.

#include <iostream>
#include <string>

//Network includes.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

// Other includes.
#include <sys/time.h>

#define PORT 9500

int main(int argc, char**args){

int socket = -1;
struct sockaddr_in servaddr;
char *serverAddress = "127.0.0.1";

socket = ::socket(AF_INET, SOCK_STREAM, 0);
if(socket == -1){
std::cout << "error: unable to create socket" << std::endl;
exit(-1);
}

bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);

inet_pton(AF_INET, serverAddress, &(servaddr.sin_addr));

// Connect ...
if(connect(socket,(const struct sockaddr *)&servaddr,sizeof(struct sockaddr_in)) == 0){

FILE *fin = fdopen(socket, "r");
FILE *fout = fdopen(socket, "w");

bool connectionError = false;

int sizeOfData = 1024;
size_t nObj = 1;

const char *outData = "(sendCommand cmd_ListenToAmp 0 0 0)\n";
int sizeOfString = strlen(outData);

int count = 0;
while(true){

int inData[sizeOfData];
if(fread(reinterpret_cast<char *>(inData), sizeOfData * sizeof(int), nObj,fin) == nObj){
std::cout << "inData count: " << inData[0] << std::endl; 
}
else{
connectionError = true;
std::cout << "client: error: read fail" << std::endl;
}

if(connectionError){
exit(0);
}

count++;
sleep(1);
}
}
else{
std::cout << "client: error: failed to connect" << std::endl;
exit(-1);
}

exit(0);
}
Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >SO_NOSIGPIPE option. (From: Robert Bell <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Vincent Lubet <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Robert Bell <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Shawn Erickson <email@hidden>)
 >Re: SO_NOSIGPIPE option. (From: Robert Bell <email@hidden>)

  • Prev by Date: Re: SO_NOSIGPIPE option.
  • Next by Date: Re: SO_NOSIGPIPE option.
  • Previous by thread: Re: SO_NOSIGPIPE option.
  • Next by thread: Re: SO_NOSIGPIPE option.
  • Index(es):
    • Date
    • Thread