| 6 | #include <scheduler.h> |
| 7 | |
| 8 | Socket* Socket::CreateSocket(int domain, int type, int protocol){ |
| 9 | if(type & SOCK_NONBLOCK) type &= ~SOCK_NONBLOCK; |
| 10 | |
| 11 | if(domain != UnixDomain && domain != InternetProtocol){ |
| 12 | Log::Warning("CreateSocket: domain %d is not supported", domain); |
| 13 | return nullptr; |
| 14 | } |
| 15 | if(type != StreamSocket && type != DatagramSocket){ |
| 16 | Log::Warning("CreateSocket: type %d is not supported", type); |
| 17 | return nullptr; |
| 18 | } |
| 19 | if(protocol){ |
| 20 | Log::Warning("CreateSocket: protocol is ignored"); |
| 21 | } |
| 22 | |
| 23 | if(domain == UnixDomain){ |
| 24 | return new LocalSocket(type, protocol); |
| 25 | } else if (domain == InternetProtocol){ |
| 26 | if(type == DatagramSocket){ |
| 27 | return new UDPSocket(type, protocol); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return nullptr; |
| 32 | } |
| 33 | |
| 34 | Socket::Socket(int type, int protocol){ |
| 35 | this->type = type; |