Skip to content

Instantly share code, notes, and snippets.

@0minus273
Last active August 29, 2015 14:05
Show Gist options
  • Save 0minus273/9a3ea608d2a406d0ffe6 to your computer and use it in GitHub Desktop.
Save 0minus273/9a3ea608d2a406d0ffe6 to your computer and use it in GitHub Desktop.
113 int i = 0;
114 int received = 0;
115 int sizenow = 4096;
116 int sizebefore = sizenow;
117 char *buffer = (char *) malloc(sizenow);
118 char *buf = buffer;
119 while ((received = read(sock, buf, 4096))>0)
120 {
121 i = i + received;
122 sizebefore = sizenow;
123 sizenow = sizenow + 4096;
124 char *newbuf = malloc(sizenow);
125 memcpy(newbuf, buffer, sizebefore);
126 buf = buf+received;
127 *buf='\0';
128 buffer = newbuf;
129 fprintf(stdout, "\n read just now: %d; current size: %d;", received, sizenow);
130 fprintf(stdout, "\n buffer now: %s;", buffer+'\0');
131 }
132 fprintf(stdout, "%s", buffer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment