MCPcopy Create free account
hub / github.com/F-Stack/f-stack / send

Method send

adapter/micro_thread/micro_thread.cpp:1328–1384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1326}
1327
1328ssize_t MtFrame::send(int fd, const void *buf, size_t nbyte, int flags, int timeout)
1329{
1330 MtFrame* mtframe = MtFrame::Instance();
1331 utime64_t start = mtframe->GetLastClock();
1332 MicroThread* thread = mtframe->GetActiveThread();
1333 utime64_t now = 0;
1334
1335 if(fd<0 || !buf || nbyte<1)
1336 {
1337 errno = EINVAL;
1338 MTLOG_ERROR("send failed, errno: %d (%m)", errno);
1339 return -10;
1340 }
1341
1342 ssize_t n = 0;
1343 size_t send_len = 0;
1344 while (send_len < nbyte)
1345 {
1346 now = mtframe->GetLastClock();
1347 if ((int)(now - start) > timeout)
1348 {
1349 errno = ETIME;
1350 return -1;
1351 }
1352
1353 mt_hook_syscall(send);
1354 n = ff_hook_send(fd, (char*)buf + send_len, nbyte - send_len, flags);
1355 if (n < 0)
1356 {
1357 if (errno == EINTR) {
1358 continue;
1359 }
1360
1361 if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) {
1362 MTLOG_ERROR("write failed, errno: %d", errno);
1363 return -2;
1364 }
1365 }
1366 else
1367 {
1368 send_len += n;
1369 if (send_len >= nbyte) {
1370 return nbyte;
1371 }
1372 }
1373
1374 KqueuerObj epfd;
1375 epfd.SetOsfd(fd);
1376 epfd.EnableOutput();
1377 epfd.SetOwnerThread(thread);
1378 if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) {
1379 return -3;
1380 }
1381 }
1382
1383 return nbyte;
1384}
1385

Callers 15

jquery.jsFile · 0.80
runTestFunction · 0.80
runHistoryTestFunction · 0.80
send_bytesMethod · 0.80
handle_socketFunction · 0.80
unregisterMethod · 0.80
requestMetricsMethod · 0.80
requestGlobalMetricsMethod · 0.80
ngx_http_test_expectFunction · 0.80

Calls 7

GetLastClockMethod · 0.80
GetActiveThreadMethod · 0.80
SetOsfdMethod · 0.80
EnableOutputMethod · 0.80
ff_hook_sendFunction · 0.70
SetOwnerThreadMethod · 0.45
KqueueScheduleMethod · 0.45

Tested by 3

runTestFunction · 0.64
runHistoryTestFunction · 0.64
send_bytesMethod · 0.64