#endif
for (;;)
{
- if (connection->service->type == CONNECTION_PIPE)
+ if (connection->service->type != CONNECTION_TCP)
{
gdb_con->buf_cnt = read(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE);
}
if (gdb_con->closed)
return ERROR_SERVER_REMOTE_CLOSED;
- if (connection->service->type == CONNECTION_PIPE)
+ if (write_socket(connection->fd_out, data, len) == len)
{
- /* write to stdout */
- if (write(STDOUT_FILENO, data, len) == len)
- {
- return ERROR_OK;
- }
- }
- else
- {
- if (write_socket(connection->fd, data, len) == len)
- {
- return ERROR_OK;
- }
+ return ERROR_OK;
}
gdb_con->closed = 1;
return ERROR_SERVER_REMOTE_CLOSED;
c = malloc(sizeof(struct connection));
c->fd = -1;
+ c->fd_out = -1;
memset(&c->sin, 0, sizeof(c->sin));
c->cmd_ctx = copy_command_context(cmd_ctx);
c->service = service;
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. */
else if (service->type == CONNECTION_PIPE)
{
c->fd = service->fd;
+ c->fd_out = fileno(stdout);
+
+ /* do not check for new connections again on stdin */
+ service->fd = -1;
/* do not check for new connections again on stdin */
service->fd = -1;
}
else if (type == CONNECTION_PIPE)
{
- /* use stdin */
- c->fd = STDIN_FILENO;
+ c->fd = fileno(stdin);
#ifdef _WIN32
/* for win32 set stdin/stdout to binary mode */
}
else
{
- if (service->type != CONNECTION_PIPE)
+ if (service->type == CONNECTION_TCP)
{
struct sockaddr_in sin;
socklen_t address_size = sizeof(sin);
struct connection
{
int fd;
+ int fd_out; /* When using pipes we're writing to a different fd */
struct sockaddr_in sin;
struct command_context *cmd_ctx;
struct service *service;
return ERROR_SERVER_REMOTE_CLOSED;
wlen = write_socket(connection->fd, data, len);
+
if (wlen == len)
return ERROR_OK;
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
- * Copyright (C) 2007,2008 Øyvind Harboe *
+ * Copyright (C) 2007-2010 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* *
* Copyright (C) 2008 by Spencer Oliver *
if (t_con->closed)
return ERROR_SERVER_REMOTE_CLOSED;
- if (write_socket(connection->fd, data, len) == len)
+ if (write_socket(connection->fd_out, data, len) == len)
{
return ERROR_OK;
}