#include "config.h"
#endif
-#include "replacements.h"
-
#include "server.h"
-
-#include "log.h"
-#include "telnet_server.h"
#include "target.h"
-#include <command.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
#include <signal.h>
+
#ifndef _WIN32
#include <netinet/tcp.h>
#endif
+
service_t *services = NULL;
/* shutdown_openocd == 1: exit the main event loop, and quit the debugger */
int add_connection(service_t *service, command_context_t *cmd_ctx)
{
- unsigned int address_size;
+ socklen_t address_size;
connection_t *c, **p;
int retval;
int flag=1;
}
else if (service->type == CONNECTION_PIPE)
{
-#ifndef _WIN32
c->fd = service->fd;
/* do not check for new connections again on stdin */
service->fd = -1;
-#endif
+
LOG_INFO("accepting '%s' connection from pipe", service->name);
if ((retval = service->new_connection(c)) != ERROR_OK)
{
LOG_WARNING("cannot change stdout mode to binary");
if (_setmode(_fileno(stdin), _O_BINARY) < 0)
LOG_WARNING("cannot change stdin mode to binary");
+ if (_setmode(_fileno(stderr), _O_BINARY) < 0)
+ LOG_WARNING("cannot change stderr mode to binary");
#else
socket_nonblock(c->fd);
#endif
kept_alive();
/* Only while we're sleeping we'll let others run */
- retval = select(fd_max + 1, &read_fds, NULL, NULL, &tv);
+ retval = socket_select(fd_max + 1, &read_fds, NULL, NULL, &tv);
openocd_sleep_postlude();
if (retval == -1)
if (service->type != CONNECTION_PIPE)
{
struct sockaddr_in sin;
- unsigned int address_size = sizeof(sin);
+ socklen_t address_size = sizeof(sin);
int tmp_fd;
tmp_fd = accept(service->fd, (struct sockaddr *)&service->sin, &address_size);
close_socket(tmp_fd);
WORD wVersionRequested;
WSADATA wsaData;
- wVersionRequested = MAKEWORD( 2, 2 );
+ wVersionRequested = MAKEWORD(2, 2);
if (WSAStartup(wVersionRequested, &wsaData) != 0)
{
exit(-1);
}
- SetConsoleCtrlHandler( ControlHandler, TRUE );
+ if (server_use_pipes == 0)
+ {
+ /* register ctrl-c handler */
+ SetConsoleCtrlHandler(ControlHandler, TRUE);
+ }
+ else
+ {
+ /* we are using pipes so ignore ctrl-c */
+ SetConsoleCtrlHandler(NULL, TRUE);
+ }
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);