diff --git a/gdb.c b/gdb.c index 8a7d7e3..31c7041 100644 --- a/gdb.c +++ b/gdb.c @@ -24,9 +24,8 @@ #include #include #include -#include -#include -#include + +#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; } diff --git a/gdb_proto.c b/gdb_proto.c index caa6004..b2747e6 100644 --- a/gdb_proto.c +++ b/gdb_proto.c @@ -19,12 +19,11 @@ #include #include #include -#include -#include #include #include #include +#include "sockets.h" #include "gdb_proto.h" #include "output.h" #include "util.h" diff --git a/gdbc.c b/gdbc.c index f14d765..6203925 100644 --- a/gdbc.c +++ b/gdbc.c @@ -19,13 +19,9 @@ #include #include #include -#include -#include -#include -#include -#include #include +#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; } diff --git a/sockets.h b/sockets.h new file mode 100644 index 0000000..84aab87 --- /dev/null +++ b/sockets.h @@ -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 +#include + +typedef int socklen_t; +#else +#include +#include +#include +#include +#include +#include + +#define closesocket close +#endif + +#endif