diff options
| author | 2012-01-17 18:27:41 -0800 | |
|---|---|---|
| committer | 2012-01-17 18:27:41 -0800 | |
| commit | 6d8dd47f2f65c4476b31672b6f2c7bbf9020fe3a (patch) | |
| tree | b572366b4ec42dba8453c5c91b4aa0b16c0ac871 | |
| parent | 73a15f4ca25453bb86d5e93c8d005e0eb3868e18 (diff) | |
Fix a bunch of uses of 'short'.
(In particular, port numbers should be unsigned short.)
Change-Id: I944eb0f8e97390f1af8094b07ee7f2a00045bd35
| -rw-r--r-- | jdwpspy/Common.h | 9 | ||||
| -rw-r--r-- | jdwpspy/Net.cpp | 6 | ||||
| -rw-r--r-- | src/globals.h | 11 | ||||
| -rw-r--r-- | src/jdwp/jdwp.h | 2 | ||||
| -rw-r--r-- | src/jdwp/jdwp_socket.cc | 32 |
5 files changed, 24 insertions, 36 deletions
diff --git a/jdwpspy/Common.h b/jdwpspy/Common.h index ddaba9c590..f942dee9a8 100644 --- a/jdwpspy/Common.h +++ b/jdwpspy/Common.h @@ -6,13 +6,14 @@ #ifndef _JDWPSPY_COMMON #define _JDWPSPY_COMMON +#include <stdint.h> #include <stdio.h> #include <sys/types.h> -typedef unsigned char u1; -typedef unsigned short u2; -typedef unsigned int u4; -typedef unsigned long long u8; +typedef uint8_t u1; +typedef uint16_t u2; +typedef uint32_t u4; +typedef uint64_t u8; #define NELEM(x) (sizeof(x) / sizeof((x)[0])) diff --git a/jdwpspy/Net.cpp b/jdwpspy/Net.cpp index eea21c8564..209cf281c9 100644 --- a/jdwpspy/Net.cpp +++ b/jdwpspy/Net.cpp @@ -53,7 +53,7 @@ typedef struct NetState { /* connect here to contact VM */ struct in_addr vmAddr; - short vmPort; + uint16_t vmPort; Peer dbg; Peer vm; @@ -227,9 +227,7 @@ void jdwpNetFree(NetState* netState); /* fwd */ * * Returns 0 on success. */ -NetState* jdwpNetStartup(unsigned short listenPort, const char* connectHost, - unsigned short connectPort) -{ +NetState* jdwpNetStartup(uint16_t listenPort, const char* connectHost, uint16_t connectPort) { NetState* netState = new NetState; memset(netState, 0, sizeof(*netState)); netState->listenSock = -1; diff --git a/src/globals.h b/src/globals.h index e5fead698b..e5b0075486 100644 --- a/src/globals.h +++ b/src/globals.h @@ -15,22 +15,13 @@ typedef uintptr_t uword; const size_t KB = 1024; const size_t MB = KB * KB; const size_t GB = KB * KB * KB; -const int kMaxInt = 0x7FFFFFFF; -const int kMinInt = -kMaxInt - 1; - -const int kCharSize = sizeof(char); -const int kShortSize = sizeof(short); -const int kIntSize = sizeof(int); -const int kDoubleSize = sizeof(double); -const int kIntptrSize = sizeof(intptr_t); + const int kWordSize = sizeof(word); const int kPointerSize = sizeof(void*); const int kBitsPerByte = 8; const int kBitsPerByteLog2 = 3; -const int kBitsPerPointer = kPointerSize * kBitsPerByte; const int kBitsPerWord = kWordSize * kBitsPerByte; -const int kBitsPerInt = kIntSize * kBitsPerByte; // Required stack alignment const int kStackAlignment = 16; diff --git a/src/jdwp/jdwp.h b/src/jdwp/jdwp.h index 03c70b05f0..ad3d077fb0 100644 --- a/src/jdwp/jdwp.h +++ b/src/jdwp/jdwp.h @@ -95,7 +95,7 @@ struct JdwpOptions { bool server; bool suspend; std::string host; - short port; + uint16_t port; }; struct JdwpEvent; diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc index d28c1da06e..d3677e86a5 100644 --- a/src/jdwp/jdwp_socket.cc +++ b/src/jdwp/jdwp_socket.cc @@ -55,12 +55,12 @@ static void netFree(JdwpNetState* state); * We only talk to one debugger at a time. */ struct JdwpNetState : public JdwpNetStateBase { - short listenPort; + uint16_t listenPort; int listenSock; /* listen for connection from debugger */ int wakePipe[2]; /* break out of select */ struct in_addr remoteAddr; - unsigned short remotePort; + uint16_t remotePort; bool awaitingHandshake; /* waiting for "JDWP-Handshake" */ @@ -80,18 +80,17 @@ struct JdwpNetState : public JdwpNetStateBase { } }; -static JdwpNetState* netStartup(short port, bool probe); +static JdwpNetState* netStartup(uint16_t port, bool probe); /* * Set up some stuff for transport=dt_socket. */ static bool prepareSocket(JdwpState* state, const JdwpOptions* options) { - unsigned short port; + uint16_t port = options->port; if (options->server) { if (options->port != 0) { /* try only the specified port */ - port = options->port; state->netState = netStartup(port, false); } else { /* scan through a range of ports, binding to the first available */ @@ -107,8 +106,7 @@ static bool prepareSocket(JdwpState* state, const JdwpOptions* options) { return false; } } else { - port = options->port; // used in a debug msg later - state->netState = netStartup(-1, false); + state->netState = netStartup(0, false); } if (options->suspend) { @@ -130,8 +128,8 @@ static bool awaitingHandshake(JdwpState* state) { /* * Initialize JDWP stuff. * - * Allocates a new state structure. If "port" is non-negative, this also - * tries to bind to a listen port. If "port" is less than zero, we assume + * Allocates a new state structure. If "port" is non-zero, this also + * tries to bind to a listen port. If "port" is zero, we assume * we're preparing for an outbound connection, and return without binding * to anything. * @@ -139,15 +137,12 @@ static bool awaitingHandshake(JdwpState* state) { * * Returns 0 on success. */ -static JdwpNetState* netStartup(short port, bool probe) { - int one = 1; +static JdwpNetState* netStartup(uint16_t port, bool probe) { JdwpNetState* netState = new JdwpNetState; - if (port < 0) { + if (port == 0) { return netState; } - CHECK_NE(port, 0); - netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (netState->listenSock < 0) { PLOG(probe ? ERROR : FATAL) << "Socket create failed"; @@ -155,9 +150,12 @@ static JdwpNetState* netStartup(short port, bool probe) { } /* allow immediate re-use */ - if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { - PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed"; - goto fail; + { + int one = 1; + if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { + PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed"; + goto fail; + } } union { |