Add a platform specific typedef for SOCKET in the peerconnection_server example since it's not universally 'int'.

R=pbos@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/33439004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7763 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org 2014-11-28 10:37:31 +00:00
parent 83b5200f95
commit 2c13f659c7
2 changed files with 12 additions and 9 deletions

View File

@ -301,7 +301,8 @@ DataSocket* ListeningSocket::Accept() const {
assert(valid()); assert(valid());
struct sockaddr_in addr = {0}; struct sockaddr_in addr = {0};
socklen_t size = sizeof(addr); socklen_t size = sizeof(addr);
int client = accept(socket_, reinterpret_cast<sockaddr*>(&addr), &size); NativeSocket client =
accept(socket_, reinterpret_cast<sockaddr*>(&addr), &size);
if (client == INVALID_SOCKET) if (client == INVALID_SOCKET)
return NULL; return NULL;

View File

@ -32,37 +32,39 @@
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
typedef int socklen_t; typedef int socklen_t;
typedef SOCKET NativeSocket;
#else #else
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/socket.h> #include <sys/socket.h>
#define closesocket close #define closesocket close
#endif typedef int NativeSocket;
#include <string>
#ifndef SOCKET_ERROR #ifndef SOCKET_ERROR
#define SOCKET_ERROR (-1) #define SOCKET_ERROR (-1)
#endif #endif
#ifndef INVALID_SOCKET #ifndef INVALID_SOCKET
#define INVALID_SOCKET static_cast<int>(~0) #define INVALID_SOCKET static_cast<NativeSocket>(-1)
#endif #endif
#endif
#include <string>
class SocketBase { class SocketBase {
public: public:
SocketBase() : socket_(INVALID_SOCKET) { } SocketBase() : socket_(INVALID_SOCKET) { }
explicit SocketBase(int socket) : socket_(socket) { } explicit SocketBase(NativeSocket socket) : socket_(socket) { }
~SocketBase() { Close(); } ~SocketBase() { Close(); }
int socket() const { return socket_; } NativeSocket socket() const { return socket_; }
bool valid() const { return socket_ != INVALID_SOCKET; } bool valid() const { return socket_ != INVALID_SOCKET; }
bool Create(); bool Create();
void Close(); void Close();
protected: protected:
int socket_; NativeSocket socket_;
}; };
// Represents an HTTP server socket. // Represents an HTTP server socket.
@ -75,7 +77,7 @@ class DataSocket : public SocketBase {
OPTIONS, OPTIONS,
}; };
explicit DataSocket(int socket) explicit DataSocket(NativeSocket socket)
: SocketBase(socket), : SocketBase(socket),
method_(INVALID), method_(INVALID),
content_length_(0) { content_length_(0) {