Skip to content

Commit

Permalink
Fix for gcc 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Apr 19, 2013
1 parent 1245cbc commit 8955221
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/fastcgi/fastcgi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct FastCgiCodec::RecordHeader
uint8_t unused;
};

const unsigned FastCgiCodec::kRecordHeader = sizeof(FastCgiCodec::RecordHeader);
const unsigned FastCgiCodec::kRecordHeader = static_cast<unsigned>(sizeof(FastCgiCodec::RecordHeader));

enum FcgiType
{
Expand Down
2 changes: 2 additions & 0 deletions muduo/base/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Singleton : boost::noncopyable
static void destroy()
{
typedef char T_must_be_complete_type[sizeof(T) == 0 ? -1 : 1];
T_must_be_complete_type dummy; (void) dummy;

delete value_;
}

Expand Down
1 change: 1 addition & 0 deletions muduo/base/ThreadLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ThreadLocal : boost::noncopyable
{
T* obj = static_cast<T*>(x);
typedef char T_must_be_complete_type[sizeof(T) == 0 ? -1 : 1];
T_must_be_complete_type dummy; (void) dummy;
delete obj;
}

Expand Down
1 change: 1 addition & 0 deletions muduo/base/ThreadLocalSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ThreadLocalSingleton : boost::noncopyable
{
assert(obj == t_value_);
typedef char T_must_be_complete_type[sizeof(T) == 0 ? -1 : 1];
T_must_be_complete_type dummy; (void) dummy;
delete t_value_;
t_value_ = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions muduo/net/Socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ void Socket::setTcpNoDelay(bool on)
{
int optval = on ? 1 : 0;
::setsockopt(sockfd_, IPPROTO_TCP, TCP_NODELAY,
&optval, sizeof optval);
&optval, static_cast<socklen_t>(sizeof optval));
// FIXME CHECK
}

void Socket::setReuseAddr(bool on)
{
int optval = on ? 1 : 0;
::setsockopt(sockfd_, SOL_SOCKET, SO_REUSEADDR,
&optval, sizeof optval);
&optval, static_cast<socklen_t>(sizeof optval));
// FIXME CHECK
}

void Socket::setKeepAlive(bool on)
{
int optval = on ? 1 : 0;
::setsockopt(sockfd_, SOL_SOCKET, SO_KEEPALIVE,
&optval, sizeof optval);
&optval, static_cast<socklen_t>(sizeof optval));
// FIXME CHECK
}

12 changes: 6 additions & 6 deletions muduo/net/SocketsOps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int sockets::createNonblockingOrDie()

void sockets::bindOrDie(int sockfd, const struct sockaddr_in& addr)
{
int ret = ::bind(sockfd, sockaddr_cast(&addr), sizeof addr);
int ret = ::bind(sockfd, sockaddr_cast(&addr), static_cast<socklen_t>(sizeof addr));
if (ret < 0)
{
LOG_SYSFATAL << "sockets::bindOrDie";
Expand All @@ -97,7 +97,7 @@ void sockets::listenOrDie(int sockfd)

int sockets::accept(int sockfd, struct sockaddr_in* addr)
{
socklen_t addrlen = sizeof *addr;
socklen_t addrlen = static_cast<socklen_t>(sizeof *addr);
#if VALGRIND
int connfd = ::accept(sockfd, sockaddr_cast(addr), &addrlen);
setNonBlockAndCloseOnExec(connfd);
Expand Down Expand Up @@ -141,7 +141,7 @@ int sockets::accept(int sockfd, struct sockaddr_in* addr)

int sockets::connect(int sockfd, const struct sockaddr_in& addr)
{
return ::connect(sockfd, sockaddr_cast(&addr), sizeof addr);
return ::connect(sockfd, sockaddr_cast(&addr), static_cast<socklen_t>(sizeof addr));
}

ssize_t sockets::read(int sockfd, void *buf, size_t count)
Expand Down Expand Up @@ -205,7 +205,7 @@ void sockets::fromIpPort(const char* ip, uint16_t port,
int sockets::getSocketError(int sockfd)
{
int optval;
socklen_t optlen = sizeof optval;
socklen_t optlen = static_cast<socklen_t>(sizeof optval);

if (::getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, &optlen) < 0)
{
Expand All @@ -221,7 +221,7 @@ struct sockaddr_in sockets::getLocalAddr(int sockfd)
{
struct sockaddr_in localaddr;
bzero(&localaddr, sizeof localaddr);
socklen_t addrlen = sizeof(localaddr);
socklen_t addrlen = static_cast<socklen_t>(sizeof localaddr);
if (::getsockname(sockfd, sockaddr_cast(&localaddr), &addrlen) < 0)
{
LOG_SYSERR << "sockets::getLocalAddr";
Expand All @@ -233,7 +233,7 @@ struct sockaddr_in sockets::getPeerAddr(int sockfd)
{
struct sockaddr_in peeraddr;
bzero(&peeraddr, sizeof peeraddr);
socklen_t addrlen = sizeof(peeraddr);
socklen_t addrlen = static_cast<socklen_t>(sizeof peeraddr);
if (::getpeername(sockfd, sockaddr_cast(&peeraddr), &addrlen) < 0)
{
LOG_SYSERR << "sockets::getPeerAddr";
Expand Down

0 comments on commit 8955221

Please sign in to comment.