151 |
151 |
152 // copy into our internal buffer |
152 // copy into our internal buffer |
153 memcpy(buf + offset, buf_ptr, buf_size); |
153 memcpy(buf + offset, buf_ptr, buf_size); |
154 } |
154 } |
155 |
155 |
156 void NetworkBufferOutput::flush_write (void) { |
156 bool NetworkBufferOutput::flush_write (void) { |
157 size_t ret; |
157 size_t ret; |
158 |
158 |
159 // ignore if we don't have any data buffered |
159 // ignore if we don't have any data buffered |
160 if (offset == 0) |
160 if (offset == 0) |
161 return; |
161 return false; |
162 |
162 |
163 // attempt to write as much as possible |
163 // attempt to write as much as possible |
164 ret = socket->send(buf, offset); |
164 ret = socket->send(buf, offset); |
165 |
165 |
166 // busy? |
166 // busy? |
167 if (ret == 0) |
167 if (ret == 0) |
168 return; |
168 return true; |
169 |
169 |
170 // trim the buffer |
170 // trim the buffer |
171 trim(ret); |
171 trim(ret); |
|
172 |
|
173 // anything left? |
|
174 return (offset > 0); |
172 } |
175 } |
173 |
176 |
174 void NetworkBufferOutput::write_prefix (char *buf, uint16_t prefix) { |
177 bool NetworkBufferOutput::write_prefix (char *buf, uint16_t prefix) { |
175 uint16_t nval = htons(prefix); |
178 uint16_t nval = htons(prefix); |
176 |
179 |
177 push_write((char*) &nval, sizeof(uint16_t)); |
180 push_write((char*) &nval, sizeof(uint16_t)); |
178 push_write(buf, prefix); |
181 push_write(buf, prefix); |
|
182 |
|
183 // anything in the buffer? |
|
184 return (offset > 0); |
179 } |
185 } |
180 |
186 |
181 void NetworkBufferOutput::write_prefix (char *buf, uint32_t prefix) { |
187 bool NetworkBufferOutput::write_prefix (char *buf, uint32_t prefix) { |
182 uint32_t nval = htonl(prefix); |
188 uint32_t nval = htonl(prefix); |
183 |
189 |
184 push_write((char*) &nval, sizeof(uint32_t)); |
190 push_write((char*) &nval, sizeof(uint32_t)); |
185 push_write(buf, prefix); |
191 push_write(buf, prefix); |
|
192 |
|
193 // anything in the buffer? |
|
194 return (offset > 0); |
186 } |
195 } |
187 |
196 |
188 |
|