Add sockets abstraction layer.
This commit is contained in:
parent
b8dd765a5b
commit
7b261217c8
15
gdb.c
15
gdb.c
|
@ -24,9 +24,8 @@
|
|||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "sockets.h"
|
||||
#include "device.h"
|
||||
#include "util.h"
|
||||
#include "opdb.h"
|
||||
|
@ -467,13 +466,13 @@ static int gdb_server(int port)
|
|||
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
printc_err("gdb: can't bind to port %d: %s\n",
|
||||
port, strerror(errno));
|
||||
close(sock);
|
||||
closesocket(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(sock, 1) < 0) {
|
||||
pr_error("gdb: can't listen on socket");
|
||||
close(sock);
|
||||
closesocket(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -483,11 +482,11 @@ static int gdb_server(int port)
|
|||
client = accept(sock, (struct sockaddr *)&addr, &len);
|
||||
if (client < 0) {
|
||||
pr_error("gdb: failed to accept connection");
|
||||
close(sock);
|
||||
closesocket(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(sock);
|
||||
closesocket(sock);
|
||||
printc("Client connected from %s:%d\n",
|
||||
inet_ntoa(addr.sin_addr), htons(addr.sin_port));
|
||||
|
||||
|
@ -505,7 +504,7 @@ static int gdb_server(int port)
|
|||
#ifdef DEBUG_GDB
|
||||
printc("... reader loop returned\n");
|
||||
#endif
|
||||
close(client);
|
||||
closesocket(client);
|
||||
|
||||
return data.error ? -1 : 0;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,11 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sockets.h"
|
||||
#include "gdb_proto.h"
|
||||
#include "output.h"
|
||||
#include "util.h"
|
||||
|
|
10
gdbc.c
10
gdbc.c
|
@ -19,13 +19,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sockets.h"
|
||||
#include "output.h"
|
||||
#include "gdbc.h"
|
||||
#include "gdb_proto.h"
|
||||
|
@ -74,7 +70,7 @@ static void gdbc_destroy(device_t dev_base)
|
|||
struct gdb_client *c = (struct gdb_client *)dev_base;
|
||||
|
||||
shutdown(c->gdb.sock, 2);
|
||||
close(c->gdb.sock);
|
||||
closesocket(c->gdb.sock);
|
||||
free(c);
|
||||
}
|
||||
|
||||
|
@ -400,7 +396,7 @@ static int connect_to(const char *spec)
|
|||
|
||||
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
printc_err("connect: %s\n", strerror(errno));
|
||||
close(sock);
|
||||
closesocket(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/* MSPDebug - debugging tool for MSP430 MCUs
|
||||
* Copyright (C) 2009, 2010 Daniel Beer
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef SOCKETS_H_
|
||||
#define SOCKETS_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef int socklen_t;
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define closesocket close
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue