Skip to content
Snippets Groups Projects
Select Git revision
  • 4b97f3cbb9603c13f69f8d3b5371c12045593126
  • max32xxx default protected
  • dw-cmsisdap-path
3 results

server.c

Blame
  • server.c 9.32 KiB
    /***************************************************************************
     *   Copyright (C) 2005 by Dominic Rath                                    *
     *   Dominic.Rath@gmx.de                                                   *
     *                                                                         *
     *   This program is free software; you can redistribute it and/or modify  *
     *   it under the terms of the GNU General Public License as published by  *
     *   the Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     *   This program is distributed in the hope that it will be useful,       *
     *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
     *   GNU General Public License for more details.                          *
     *                                                                         *
     *   You should have received a copy of the GNU General Public License     *
     *   along with this program; if not, write to the                         *
     *   Free Software Foundation, Inc.,                                       *
     *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
     ***************************************************************************/
    #ifdef HAVE_CONFIG_H
    #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>
    
    service_t *services = NULL;
    
    /* shutdown_openocd == 1: exit the main event loop, and quit the debugger */
    static int shutdown_openocd = 0;
    int handle_shutdown_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
    
    int add_connection(service_t *service, command_context_t *cmd_ctx)
    {
    	unsigned int address_size;
    	connection_t *c, *p;
    	int retval;
    	
    	c = malloc(sizeof(connection_t));
    	c->fd = -1;
    	memset(&c->sin, 0, sizeof(c->sin));
    	c->cmd_ctx = copy_command_context(cmd_ctx);
    	c->service = service;
    	c->input_pending = 0;
    	c->priv = NULL;
    	c->next = NULL;
    
    	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
    	{