- address_size = sizeof(c->sin);
- c->fd = accept(service->fd, (struct sockaddr *)&service->sin, &address_size);
-
- if ((retval = service->new_connection(c)) == ERROR_OK)
- {
- INFO("accepted '%s' connection from %i", service->name, c->sin.sin_port);
- }
- else
- {
- close_socket(c->fd);
- INFO("attempted '%s' connection rejected", service->name);
- free(c);
- }
-
- if (service->connections)
- {
- for (p = service->connections; p && p->next; p = p->next);
- if (p)
- p->next = c;
- }
- else
- {
- service->connections = c;
+ if (service->type == CONNECTION_TCP) {
+ address_size = sizeof(c->sin);
+
+ c->fd = accept(service->fd, (struct sockaddr *)&service->sin, &address_size);
+ c->fd_out = c->fd;
+
+ /* This increases performance dramatically for e.g. GDB load which
+ * does not have a sliding window protocol.
+ *
+ * Ignore errors from this fn as it probably just means less performance
+ */
+ setsockopt(c->fd, /* socket affected */
+ IPPROTO_TCP, /* set option at TCP level */
+ TCP_NODELAY, /* name of option */
+ (char *)&flag, /* the cast is historical cruft */
+ sizeof(int)); /* length of option value */
+
+ LOG_INFO("accepting '%s' connection from %s", service->name, service->port);
+ retval = service->new_connection(c);
+ if (retval != ERROR_OK) {
+ close_socket(c->fd);
+ LOG_ERROR("attempted '%s' connection rejected", service->name);
+ command_done(c->cmd_ctx);
+ free(c);
+ return retval;
+ }
+ } else if (service->type == CONNECTION_STDINOUT) {
+ c->fd = service->fd;
+ c->fd_out = fileno(stdout);
+
+#ifdef _WIN32
+ /* we are using stdin/out so ignore ctrl-c under windoze */
+ SetConsoleCtrlHandler(NULL, TRUE);
+#endif
+
+ /* do not check for new connections again on stdin */
+ service->fd = -1;
+
+ LOG_INFO("accepting '%s' connection from pipe", service->name);
+ retval = service->new_connection(c);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("attempted '%s' connection rejected", service->name);
+ command_done(c->cmd_ctx);
+ free(c);
+ return retval;
+ }
+ } else if (service->type == CONNECTION_PIPE) {
+ c->fd = service->fd;
+ /* do not check for new connections again on stdin */
+ service->fd = -1;
+
+ char *out_file = alloc_printf("%so", service->port);
+ c->fd_out = open(out_file, O_WRONLY);
+ free(out_file);
+ if (c->fd_out == -1) {
+ LOG_ERROR("could not open %s", service->port);
+ exit(1);
+ }
+
+ LOG_INFO("accepting '%s' connection from pipe %s", service->name, service->port);
+ retval = service->new_connection(c);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("attempted '%s' connection rejected", service->name);
+ command_done(c->cmd_ctx);
+ free(c);
+ return retval;
+ }