+void gdbserver_t::write()
+{
+ if (send_buf.empty())
+ return;
+
+ while (!send_buf.empty()) {
+ unsigned int count = send_buf.contiguous_data_size();
+ assert(count > 0);
+ ssize_t bytes = ::write(client_fd, send_buf.contiguous_data(), count);
+ if (bytes == -1) {
+ fprintf(stderr, "failed to write to socket: %s (%d)\n", strerror(errno), errno);
+ abort();
+ } else if (bytes == 0) {
+ // Client can't take any more data right now.
+ break;
+ } else {
+ printf("wrote %ld bytes:\n", bytes);
+ for (unsigned int i = 0; i < bytes; i++) {
+ printf("%c", send_buf[i]);
+ }
+ printf("\n");
+ send_buf.consume(bytes);
+ }
+ }
+}
+