I need to be able to do asynchronous io with sockets using exec signals, but I can't get it to work. The ISocket->SocketBaseTags() should set up bsdlibrary to send exec signals, but the signal never arrives. If you remove the IExec->Wait() statement, the code works of course...
/* * __socketpair_tcp(): Create a socket pipe. */ int __socketpair_tcp(int fd[2]) { int listener; struct sockaddr sock; socklen_t socklen = sizeof(sock); int len = socklen; int one = 1; int connect_done = 0;
(Note, that this is a test scenario, so don't get too hung up on the code actually making any practical sense. It is just the same thread reading and writing to/from the same socket pair.)
Your code is missing the setsockopt() call to tell the TCP/IP stack in which events you are interested in. Without that it has to assume you are interested in nothing and hence will never Signal() your application. Refer to the GetSocketEvents docs for more details.
Thanks for the info! Still, I don't quite understand how it is supposed to work: The "getsockopt()" entry in the docs don't mention anything about SO_EVENTMASK as mentioned in the GetSocketEvents() entry, which makes me a little confused. Could you give an example, maybe??
EDIT: I tried inserting the following line, but it changes nothing:
int main(int argc, char* argv[]) { int sockd; int count; struct sockaddr_in serv_name; char buf[MAX_BUF]; int status;
/* create a socket */ sockd = socket(AF_INET, SOCK_DGRAM, 0); if (sockd == -1) { perror("Socket creation"); exit(1); }
/* server address */ serv_name.sin_family = AF_INET; struct hostent *hent = gethostbyname("www.google.com"); if (!hent) { perror ("gethostbyname failed"); exit(-1); } if (hent->h_addrtype != AF_INET) { perror("Unknown address type"); exit(-1); }
printf("hostname = %s\n", hent->h_name);
//What is supposed to happen here??? //serv_name.sin_addr.s_addr = inet_addr(hent->h_addr_list[0]); memcpy (&(serv_name.sin_addr.s_addr), hent->h_addr, hent->h_length); serv_name.sin_port = htons (12345);
/* connect to the server */ status = connect(sockd, (struct sockaddr*)&serv_name, sizeof(serv_name)); if (status == -1) { perror("Connection error"); exit(1); } printf("connected to server\n");