Fixed bug with non-blocking call to connect() for integrated http client.

Cleaned up some debugging stuff.
This commit is contained in:
gardners 2012-01-12 17:02:22 +10:30
parent 90729e20b6
commit 7bcc852279
3 changed files with 16 additions and 9 deletions

View File

@ -299,9 +299,6 @@ int overlay_rx_messages()
{
if (debug&DEBUG_OVERLAYINTERFACES)
fprintf(stderr,"At end of input on dummy interface #%d\n",i);
char c;
int r=read(overlay_interfaces[i].fd,&c,1);
fprintf(stderr,"r=%d\n",r);
}
else
{

View File

@ -128,9 +128,12 @@ int rhizome_queue_manifest_import(rhizome_manifest *m,
bcopy(peerip,&peeraddr,sizeof(peeraddr));
peeraddr.sin_port=htons(RHIZOME_HTTP_PORT);
int r=connect(sock,(struct sockaddr*)&peeraddr,sizeof(peeraddr));
if (r!=EINPROGRESS||(r!=0)) {
if ((errno!=EINPROGRESS)&&(r!=0)) {
close (sock);
WHY("Failed to open socket to peer's rhizome web server");
if (debug&DEBUG_RHIZOME) {
WHY("Failed to open socket to peer's rhizome web server");
perror("connect");
}
return -1;
}
file_fetch_queue[rhizome_file_fetch_queue_count].manifest=m;

View File

@ -78,10 +78,13 @@ int rhizome_server_start()
{
if (rhizome_server_socket>-1) return 0;
/* Only try to start http server periodically */
if (rhizome_server_socket<-1) { rhizome_server_socket++; return -1; }
struct sockaddr_in address;
int on=1;
WHY("Started rhizome server");
if (debug&DEBUG_RHIZOME) fprintf(stderr,"Trying to start rhizome server.\n");
/* Catch broken pipe signals */
signal(SIGPIPE,sigPipeHandler);
@ -89,7 +92,10 @@ int rhizome_server_start()
rhizome_server_socket=socket(AF_INET,SOCK_STREAM,0);
if (rhizome_server_socket<0)
return WHY("socket() failed starting rhizome http server");
{
rhizome_server_socket=-1000;
return WHY("socket() failed starting rhizome http server");
}
setsockopt(rhizome_server_socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on));
@ -102,8 +108,9 @@ int rhizome_server_start()
sizeof(address)) < 0)
{
close(rhizome_server_socket);
rhizome_server_socket=-1;
return WHY("bind() failed starting rhizome http server\n");
rhizome_server_socket=-1000;
if (debug&DEBUG_RHIZOME) WHY("bind() failed starting rhizome http server\n");
return -1;
}
int rc = ioctl(rhizome_server_socket, FIONBIO, (char *)&on);