MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxOpenNetwork

Function fxOpenNetwork

tools/serial2xsbug/serial2xsbug_lin.c:85–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85txSerialMachine fxOpenNetwork(txSerialTool self, uint32_t value)
86{
87 txSerialMachine* link = &(self->firstMachine);
88 txSerialMachine machine;
89 while ((machine = *link)) {
90 if (machine->value == value)
91 break;
92 link = &(machine->nextMachine);
93 }
94 if (!machine) {
95 struct hostent *host;
96 struct sockaddr_in address;
97
98 if (self->count == 1 + mxMachinesCount)
99 mxThrowError(ENOMEM);
100
101 machine = calloc(sizeof(txSerialMachineRecord), 1);
102 mxThrowElse(machine != NULL);
103 machine->tool = self;
104 machine->value = value;
105 sprintf(machine->tag, "?xs.%8.8X?>\r\n<", value);
106 *link = machine;
107
108 host = gethostbyname(self->host);
109 mxThrowElse(host != NULL);
110 memset(&address, 0, sizeof(address));
111 address.sin_family = AF_INET;
112 memcpy(&(address.sin_addr), host->h_addr, host->h_length);
113 address.sin_port = htons(self->port);
114 machine->networkConnection = socket(AF_INET, SOCK_STREAM, 0);
115 mxThrowElse(machine->networkConnection >= 0);
116 mxThrowElse(connect(machine->networkConnection, (struct sockaddr*)&address, sizeof(address)) >= 0);
117
118 fxCountMachines(self);
119 }
120 machine->receiveCount += 1;
121 return machine;
122}
123
124void fxOpenSerial(txSerialTool self)
125{

Callers

nothing calls this directly

Calls 2

fxCountMachinesFunction · 0.70
connectFunction · 0.50

Tested by

no test coverage detected