forking socket

Atomical
Unregistered
 
Post: #1
I'm running my code through Xcode's debugger and I'm having problems. I forked the socket and it appears to be working right as I have stepped through the first part of the program that forked and am now inside the function I designated for the fork.

Code:
int bufvalue = 0;
char *buf = (char *)malloc(2000*sizeof(char)+1);
//read the info from the client  
while ( (charsread = recv(sock, buf, 2000, 0)) != 0 && charsread != -1 ) {
    header = (char *)realloc(header,(bufvalue+=strlen(buf))*sizeof(char)+1);
    strcat(header,buf);
    bzero(buf,strlen(buf));
}

Once I get to this part it runs through the code once and on the second time it says Stepping... at the status bar at the top and just stops. No segfault happens. It just hangs.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
recv blocks until there's data on the socket, doesn't it? could that be happening?
if you pause, what function is it in?
Quote this message in a reply
Atomical
Unregistered
 
Post: #3
void dostuff (int sock, storage* ads)

I think I know what you're saying. However, it is loading all the data that my php script is sending to it. I verified that with Xcodes panel to the upper right.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
The exit condition for the while loop is when the stream goes dry right? I haven't used streams in C much, so I'm guessing that recv() returning -1 means EOF right? If that is the case, are you closing the stream on the other end?
Quote this message in a reply
Atomical
Unregistered
 
Post: #5
I need to keep the stream open so I can send data back to it.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Atomical Wrote:I need to keep the stream open so I can send data back to it.
Back from the C-side? If it's bidirectional, then you actually have two separate parts of the socket don't you? At least in Ruby, when you have a stream with input and output, you can close the only the read or write end stream. You send something, close the write end so that the other side gets an EOF. When the other side is done it closes it's end so that the first side gets an EOF and goes along it's merry way.

Is that the way streams work in C too?
Quote this message in a reply
Atomical
Unregistered
 
Post: #7
I don't think so.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ruby: Socket woes Skorche 2 3,382 Jun 26, 2004 10:16 AM
Last Post: Skorche