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

Function xs_serial_write

modules/io/serial/mac/serial.c:237–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237void xs_serial_write(xsMachine *the)
238{
239 xsSerial s = xsmcGetHostData(xsThis);
240 xsUnsignedValue count = 0;
241 void *data;
242 char byte;
243
244 if (1 == s->bufferFormat) {
245 xsmcGetBufferReadable(xsArg(0), &data, &count);
246 }
247 else if (2 == s->bufferFormat) {
248 count = 1;
249 byte = xsmcToInteger(xsArg(0));
250 data = &byte;
251 }
252 if (!count)
253 return;
254
255 if ((count > kWriteBufferSize) || s->flush)
256 xsUnknownError("would overflow");
257
258 while (count) {
259 int result = write(s->fd, data, count);
260 if (result < 0) {
261 if (EAGAIN != errno)
262 xsUnknownError("write failed");
263
264 c_memmove(s->writeBuffer, data, count);
265 s->toWrite = s->writeBuffer;
266 s->bytesToWrite = count;
267
268 s->flush = modTimerAdd(0, 0, fxSerialFlush, &s, sizeof(s));
269 return;
270 }
271 count -= result;
272 data += result;
273 }
274
275 if (!s->writable && s->hasOnWritable)
276 s->writable = modTimerAdd(0, 0, fxSerialWritable, &s, sizeof(s));
277}
278
279void xs_serial_set(xsMachine *the)
280{

Callers

nothing calls this directly

Calls 2

writeFunction · 0.50
modTimerAddFunction · 0.50

Tested by

no test coverage detected