Skip to content

Instantly share code, notes, and snippets.

View shi-yan's full-sized avatar
💭
keyboard smashing

Shi Yan shi-yan

💭
keyboard smashing
View GitHub Profile
@shi-yan
shi-yan / protobuf_qt
Last active August 9, 2022 14:32
Build Protobuf files as a prebuild step of qmake (support protobuf in Qt)
#both protopath and protos need to use the relative path.
#otherwise you will see this protobuf compiler message:
#You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix
#of the .proto file names -- protoc is too dumb to figure out when two paths
# (e.g. absolute and relative) are equivalent (it's harder than you think).
PROTOPATH += ../../../../common/protocols/protos #this is the folder contains *.proto
PROTOPATHS =
for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
PROTOS += ../../../../common/protocols/protos/xxx.proto #the actual *.proto files need to be compiled.
@shi-yan
shi-yan / keepalive
Created September 17, 2014 23:36
Correct way to set tcp socket keepalive on Win, Mac and Linux. Verified with Wireshark.
void setTcpKeepalive(SOCKET &sockfd)
{
const uint32_t keepaliveIntervalSec = 10;
#ifdef _WIN32
tcp_keepalive keepaliveParams;
DWORD ret = 0;
keepaliveParams.onoff = 1;
keepaliveParams.keepaliveinterval = keepaliveParams.keepalivetime = keepaliveIntervalSec * 1000;
WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, &keepaliveParams, sizeof(keepaliveParams), NULL, 0, &ret, NULL, NULL);