repositories
/
deb_libcec.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9b53a14
)
posix: fixed lib/platform/sockets/tcp.h compilation and some bugs. added CTcpSocket...
author
Lars Op den Kamp
<lars@opdenkamp.eu>
Mon, 30 Jan 2012 11:15:47 +0000
(12:15 +0100)
committer
Lars Op den Kamp
<lars@opdenkamp.eu>
Mon, 30 Jan 2012 12:42:15 +0000
(13:42 +0100)
src/lib/platform/posix/os-socket.h
patch
|
blob
|
blame
|
history
src/lib/platform/posix/os-tcp.h
patch
|
blob
|
blame
|
history
src/lib/platform/sockets/socket.h
patch
|
blob
|
blame
|
history
src/lib/platform/sockets/tcp.h
patch
|
blob
|
blame
|
history
src/lib/platform/windows/os-tcp.h
patch
|
blob
|
blame
|
history
diff --git
a/src/lib/platform/posix/os-socket.h
b/src/lib/platform/posix/os-socket.h
index a57f69d21d449103b49b40b8c25ed81c74fc8bb5..9d557c1b4583a9bc631642f60e38036910f04cef 100644
(file)
--- a/
src/lib/platform/posix/os-socket.h
+++ b/
src/lib/platform/posix/os-socket.h
@@
-64,7
+64,7
@@
namespace PLATFORM
}
int64_t iBytesWritten = 0;
}
int64_t iBytesWritten = 0;
- struct timeval *tv;
+ struct timeval *tv
(NULL)
;
while (iBytesWritten < len)
{
while (iBytesWritten < len)
{
diff --git
a/src/lib/platform/posix/os-tcp.h
b/src/lib/platform/posix/os-tcp.h
index eb9774c01e9d2dafbf7c2efdd41618b42e4f33c7..86d0603916e6357250b8f0ae42c48b80673711a4 100644
(file)
--- a/
src/lib/platform/posix/os-tcp.h
+++ b/
src/lib/platform/posix/os-tcp.h
@@
-34,8
+34,20
@@
#include "../os.h"
#include "../sockets/socket.h"
#include "../os.h"
#include "../sockets/socket.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <poll.h>
+
namespace PLATFORM
{
namespace PLATFORM
{
+ inline void TcpShutdownSocket(socket_t socket)
+ {
+ shutdown(socket, SHUT_RDWR);
+ }
+
inline int TcpGetSocketError(socket_t socket)
{
int iReturn(0);
inline int TcpGetSocketError(socket_t socket)
{
int iReturn(0);
@@
-67,13
+79,17
@@
namespace PLATFORM
else if (iPollResult == -1)
*iError = errno;
else
else if (iPollResult == -1)
*iError = errno;
else
- *iError = TcpGetSocketError(socket);
+ bConnected = true;
+ }
+ else
+ {
+ *iError = errno;
}
return bConnected;
}
}
return bConnected;
}
- inline bool TcpResolveAddress(const char *strHost, uint16_t iPort, int *iError, struct addrinfo *info)
+ inline bool TcpResolveAddress(const char *strHost, uint16_t iPort, int *iError, struct addrinfo *
*
info)
{
struct addrinfo hints;
char service[33];
{
struct addrinfo hints;
char service[33];
@@
-83,6
+99,7
@@
namespace PLATFORM
hints.ai_protocol = IPPROTO_TCP;
sprintf(service, "%d", iPort);
hints.ai_protocol = IPPROTO_TCP;
sprintf(service, "%d", iPort);
- return ((*iError = getaddrinfo(strHost, service, &hints, &info)) == 0);
+ *iError = getaddrinfo(strHost, service, &hints, info);
+ return !(*iError);
}
}
}
}
diff --git
a/src/lib/platform/sockets/socket.h
b/src/lib/platform/sockets/socket.h
index 530bd1be770d64a4ad617641b95fa805b9dbe55f..2e8acdbdca4de00fb7b76822b0ed36214c870d9f 100644
(file)
--- a/
src/lib/platform/sockets/socket.h
+++ b/
src/lib/platform/sockets/socket.h
@@
-48,7
+48,9
@@
namespace PLATFORM
{
public:
CSocket(void) :
{
public:
CSocket(void) :
- m_socket(INVALID_SOCKET) {};
+ m_socket(INVALID_SOCKET),
+ m_iError(0) {};
+
virtual ~CSocket(void)
{
Close();
virtual ~CSocket(void)
{
Close();
@@
-72,18
+74,16
@@
namespace PLATFORM
virtual int64_t Write(uint8_t* data, uint32_t len)
{
CLockObject lock(m_mutex);
virtual int64_t Write(uint8_t* data, uint32_t len)
{
CLockObject lock(m_mutex);
- int iError(0);
- int64_t iReturn = SocketWrite(m_socket, &iError, data, len);
- m_strError = strerror(iError);
+ int64_t iReturn = SocketWrite(m_socket, &m_iError, data, len);
+ m_strError = strerror(m_iError);
return iReturn;
}
virtual int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0)
{
CLockObject lock(m_mutex);
return iReturn;
}
virtual int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0)
{
CLockObject lock(m_mutex);
- int iError(0);
- int32_t iReturn = SocketRead(m_socket, &iError, data, len, iTimeoutMs);
- m_strError = strerror(iError);
+ int32_t iReturn = SocketRead(m_socket, &m_iError, data, len, iTimeoutMs);
+ m_strError = strerror(m_iError);
return iReturn;
}
return iReturn;
}
@@
-94,9
+94,15
@@
namespace PLATFORM
return strReturn;
}
return strReturn;
}
+ virtual int GetErrorNumber(void) const
+ {
+ return m_iError;
+ }
+
protected:
socket_t m_socket;
CStdString m_strError;
protected:
socket_t m_socket;
CStdString m_strError;
+ int m_iError;
CMutex m_mutex;
};
};
CMutex m_mutex;
};
};
diff --git
a/src/lib/platform/sockets/tcp.h
b/src/lib/platform/sockets/tcp.h
index 47c71b7754eeb3e0b043df9bfd3172a4d07fdc52..ef9c418aaa82568d7b24008e0e8be5c487605add 100644
(file)
--- a/
src/lib/platform/sockets/tcp.h
+++ b/
src/lib/platform/sockets/tcp.h
@@
-39,52
+39,62
@@
#include "../posix/os-tcp.h"
#endif
#include "../posix/os-tcp.h"
#endif
+using namespace std;
+
namespace PLATFORM
{
class CTcpSocket : public CSocket
{
public:
namespace PLATFORM
{
class CTcpSocket : public CSocket
{
public:
- CTcpSocket(void);
+ CTcpSocket(void)
{}
;
virtual ~CTcpSocket(void) {}
virtual bool Open(const CStdString &strHostname, uint16_t iPort, uint64_t nTimeout)
{
bool bReturn(false);
virtual ~CTcpSocket(void) {}
virtual bool Open(const CStdString &strHostname, uint16_t iPort, uint64_t nTimeout)
{
bool bReturn(false);
- struct addrinfo *address
, *addr
;
-
int iResult = TcpResolveAddress(strHostname, iPort, address
);
- if (
iResult
)
+ struct addrinfo *address
(NULL), *addr(NULL)
;
+
CLockObject lock(m_mutex
);
+ if (
!TcpResolveAddress(strHostname.c_str(), iPort, &m_iError, &address)
)
{
{
- m_strError = strerror(
iResult
);
+ m_strError = strerror(
m_iError
);
return bReturn;
}
for(addr = address; !bReturn && addr; addr = addr->ai_next)
{
return bReturn;
}
for(addr = address; !bReturn && addr; addr = addr->ai_next)
{
- int iError(0);
- m_socket = TcpCreateSocket(addr, &iError, nTimeout);
+ m_socket = TcpCreateSocket(addr, &m_iError, nTimeout);
if (m_socket != INVALID_SOCKET && m_socket != SOCKET_ERROR)
bReturn = true;
else
if (m_socket != INVALID_SOCKET && m_socket != SOCKET_ERROR)
bReturn = true;
else
- m_strError = strerror(iError);
+ m_strError = strerror(
m_
iError);
}
freeaddrinfo(address);
return bReturn;
}
}
freeaddrinfo(address);
return bReturn;
}
+ virtual void Shutdown(void)
+ {
+ CLockObject lock(m_mutex);
+ if (m_socket != INVALID_SOCKET && m_socket != SOCKET_ERROR)
+ TcpShutdownSocket(m_socket);
+ m_socket = INVALID_SOCKET;
+ m_strError = "";
+ }
+
protected:
virtual socket_t TcpCreateSocket(struct addrinfo* addr, int* iError, uint64_t iTimeout)
{
socket_t fdSock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
protected:
virtual socket_t TcpCreateSocket(struct addrinfo* addr, int* iError, uint64_t iTimeout)
{
socket_t fdSock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
- if (fdSock ==
-1
)
+ if (fdSock ==
INVALID_SOCKET || fdSock == SOCKET_ERROR
)
{
{
- *iError =
TcpGetSocketError()
;
+ *iError =
errno
;
return (socket_t)SOCKET_ERROR;
}
return (socket_t)SOCKET_ERROR;
}
- if (
TcpConnectSocket(addr, fdSock, iError, iTimeout) != 0
)
+ if (
!TcpConnectSocket(fdSock, addr, iError, iTimeout)
)
{
{
-
closesocket
(fdSock);
+
SocketClose
(fdSock);
return (socket_t)SOCKET_ERROR;
}
return (socket_t)SOCKET_ERROR;
}
diff --git
a/src/lib/platform/windows/os-tcp.h
b/src/lib/platform/windows/os-tcp.h
index 299ce379e8abab8015b0015cf4817a8e6dc76256..b05a3ddb0e2c2e4bbb437fe956b1921941aa611e 100644
(file)
--- a/
src/lib/platform/windows/os-tcp.h
+++ b/
src/lib/platform/windows/os-tcp.h
@@
-36,6
+36,11
@@
namespace PLATFORM
{
namespace PLATFORM
{
+ inline void TcpShutdownSocket(socket_t socket)
+ {
+ shutdown(socket, SHUT_RDWR);
+ }
+
inline int TcpResolveAddress(const CStdString &strHostname, uint16_t iPort, struct addrinfo *address)
{
struct addrinfo hints;
inline int TcpResolveAddress(const CStdString &strHostname, uint16_t iPort, struct addrinfo *address)
{
struct addrinfo hints;