| 133 | } |
| 134 | |
| 135 | void xs_socket(xsMachine *the) |
| 136 | { |
| 137 | xsSocket xss; |
| 138 | qurt_thread_attr_t attr; |
| 139 | qurt_thread_t thread; |
| 140 | uint8_t result; |
| 141 | int ttl = 0; |
| 142 | int port = 0; |
| 143 | uint32_t multiaddr; |
| 144 | struct sockaddr_in address; |
| 145 | |
| 146 | xsmcVars(1); |
| 147 | if (xsmcHas(xsArg(0), xsID_listener)) { |
| 148 | xsListener xsl; |
| 149 | xsmcGet(xsVar(0), xsArg(0), xsID_listener); |
| 150 | xsl = xsmcGetHostData(xsVar(0)); |
| 151 | xss = xsl->pending; |
| 152 | xsl->pending = NULL; |
| 153 | |
| 154 | xss->obj = xsThis; |
| 155 | xsmcSetHostData(xsThis, xss); |
| 156 | xsRemember(xss->obj); |
| 157 | |
| 158 | modInstrumentationAdjust(NetworkSockets, 1); |
| 159 | |
| 160 | if (!gSockets) |
| 161 | gSockets = xss; |
| 162 | else { |
| 163 | xss->next = gSockets; |
| 164 | gSockets = xss; |
| 165 | } |
| 166 | |
| 167 | if (NULL == gTimer) |
| 168 | gTimer = modTimerAdd(0, 20, socketTimerCallback, NULL, 0); |
| 169 | |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | xss = c_calloc(sizeof(xsSocketRecord), 1); |
| 174 | if (!xss) |
| 175 | xsUnknownError("no memory"); |
| 176 | |
| 177 | xsmcSetHostData(xsThis, xss); |
| 178 | |
| 179 | xss->obj = xsThis; |
| 180 | xss->the = the; |
| 181 | xss->useCount = 1; |
| 182 | |
| 183 | xss->kind = kTCP; |
| 184 | if (xsmcHas(xsArg(0), xsID_kind)) { |
| 185 | char *kind; |
| 186 | |
| 187 | xsmcGet(xsVar(0), xsArg(0), xsID_kind); |
| 188 | kind = xsmcToString(xsVar(0)); |
| 189 | if (0 == c_strcmp(kind, "TCP")) |
| 190 | ; |
| 191 | else if (0 == c_strcmp(kind, "UDP")) { |
| 192 | xss->kind = kUDP; |
nothing calls this directly
no test coverage detected