MCPcopy Create free account
hub / github.com/F-Stack/f-stack / CreateSock

Method CreateSock

adapter/micro_thread/mt_net.cpp:833–880  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

831}
832
833int32_t CSockLink::CreateSock()
834{
835 if (_fd > 0)
836 {
837 return _fd;
838 }
839
840 if (NET_PROTO_TCP == _proto_type)
841 {
842 _fd = socket(AF_INET, SOCK_STREAM, 0);
843 }
844 else
845 {
846 _fd = socket(AF_INET, SOCK_DGRAM, 0);
847 }
848
849 if (_fd < 0)
850 {
851 MTLOG_ERROR("create socket failed, ret %d[%m]", _fd);
852 return -1;
853 }
854
855 int flags = 1;
856 if (ioctl(_fd, FIONBIO, &flags) < 0)
857 {
858 MTLOG_ERROR("socket unblock failed, %m");
859 close(_fd);
860 _fd = -1;
861 return -2;
862 }
863
864 if (NET_PROTO_TCP == _proto_type)
865 {
866 setsockopt(_fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof(flags));
867 this->EnableOutput();
868 }
869
870 this->EnableInput();
871 if (!MtFrame::Instance()->KqueueAddObj(this))
872 {
873 MTLOG_ERROR("socket epoll mng failed, %m");
874 close(_fd);
875 _fd = -1;
876 return -3;
877 }
878
879 return _fd;
880}
881
882struct sockaddr_in* CSockLink::GetDestAddr(struct sockaddr_in* addr)
883{

Callers 1

WaitConnectMethod · 0.80

Calls 7

EnableOutputMethod · 0.80
EnableInputMethod · 0.80
KqueueAddObjMethod · 0.80
socketFunction · 0.70
ioctlFunction · 0.70
closeFunction · 0.70
setsockoptFunction · 0.70

Tested by

no test coverage detected