| 1063 | } |
| 1064 | |
| 1065 | int sal_socket(int domain, int type, int protocol) |
| 1066 | { |
| 1067 | int retval; |
| 1068 | int socket, proto_socket; |
| 1069 | struct sal_socket *sock; |
| 1070 | struct sal_proto_family *pf; |
| 1071 | |
| 1072 | /* allocate a new socket and registered socket options */ |
| 1073 | socket = socket_new(); |
| 1074 | if (socket < 0) |
| 1075 | { |
| 1076 | return -1; |
| 1077 | } |
| 1078 | |
| 1079 | /* get sal socket object by socket descriptor */ |
| 1080 | sock = sal_get_socket(socket); |
| 1081 | if (sock == RT_NULL) |
| 1082 | { |
| 1083 | socket_delete(socket); |
| 1084 | return -1; |
| 1085 | } |
| 1086 | |
| 1087 | /* Initialize sal socket object */ |
| 1088 | retval = socket_init(domain, type, protocol, &sock); |
| 1089 | if (retval < 0) |
| 1090 | { |
| 1091 | LOG_E("SAL socket protocol family input failed, return error %d.", retval); |
| 1092 | socket_delete(socket); |
| 1093 | return retval; |
| 1094 | } |
| 1095 | |
| 1096 | /* valid the network interface socket opreation */ |
| 1097 | SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, socket); |
| 1098 | |
| 1099 | proto_socket = pf->skt_ops->socket(domain, type, protocol); |
| 1100 | if (proto_socket >= 0) |
| 1101 | { |
| 1102 | #ifdef SAL_USING_TLS |
| 1103 | if (SAL_SOCKOPS_PROTO_TLS_VALID(sock, socket)) |
| 1104 | { |
| 1105 | sock->user_data_tls = proto_tls->ops->socket(socket); |
| 1106 | if (sock->user_data_tls == RT_NULL) |
| 1107 | { |
| 1108 | socket_delete(socket); |
| 1109 | return -1; |
| 1110 | } |
| 1111 | } |
| 1112 | #endif |
| 1113 | sock->user_data = (void *)(size_t)proto_socket; |
| 1114 | return sock->socket; |
| 1115 | } |
| 1116 | socket_delete(socket); |
| 1117 | return -1; |
| 1118 | } |
| 1119 | |
| 1120 | int sal_socketpair(int domain, int type, int protocol, int *fds) |
| 1121 | { |
no test coverage detected