The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: Sback | October 7, 2010 @ 5:59am
C Code
[
Download
]
void recv_data(int sd, char **buffer) { int int_buf_size = 10; char int_buf[int_buf_size]; char *up_to_now = NULL; int num_of_bytes_written = 0; int num_of_bytes_received = 0; int done = 0; do { num_of_bytes_received = recv(sd, int_buf, int_buf_size, 0); assert(num_of_bytes_received!=-1); if (num_of_bytes_received == 0) { done = 1; } else { printf("bytes received = %d \n",num_of_bytes_received); up_to_now = realloc(up_to_now, num_of_bytes_received); memcpy(&up_to_now[num_of_bytes_written], int_buf, num_of_bytes_received); printf("bytes written = %d \n",num_of_bytes_written); num_of_bytes_written = num_of_bytes_written + num_of_bytes_received; printf("bytes written = %d \n",num_of_bytes_written); printf("%s\n",up_to_now); } } while (!done); printf("bytes written final = %d \n",num_of_bytes_written); *buffer = malloc(num_of_bytes_written); memcpy(*buffer,up_to_now,num_of_bytes_written); printf("%s\n",*buffer); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.48 / 8
56 Votes
http://codebin.yi.org/882
page generated in 0.01 seconds