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

Function mt_tcpsend_short

adapter/micro_thread/mt_api.cpp:387–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385}
386
387int mt_tcpsend_short(struct sockaddr_in* dst, void* pkg, int len, int timeout)
388{
389 if (!dst || !pkg || len<1)
390 {
391 MTLOG_ERROR("input params invalid, dst[%p], pkg[%p], len[%d]", dst, pkg, len);
392 return -10;
393 }
394
395 int ret = 0, rc = 0;
396 int addr_len = sizeof(struct sockaddr_in);
397 utime64_t start_ms = MtFrame::Instance()->GetLastClock();
398 utime64_t cost_time = 0;
399 int time_left = timeout;
400
401 int sock = -1;
402 sock = mt_tcp_create_sock();
403 if (sock < 0)
404 {
405 MTLOG_ERROR("create tcp socket failed, ret: %d", sock);
406 ret = -1;
407 goto EXIT_LABEL;
408 }
409
410 rc = MtFrame::connect(sock, (struct sockaddr *)dst, addr_len, time_left);
411 if (rc < 0)
412 {
413 MTLOG_ERROR("socket[%d] connect failed, ret[%d][%m]", sock, rc);
414 ret = -4;
415 goto EXIT_LABEL;
416 }
417
418 cost_time = MtFrame::Instance()->GetLastClock() - start_ms;
419 time_left = (timeout > (int)cost_time) ? (timeout - (int)cost_time) : 0;
420 rc = MtFrame::send(sock, pkg, len, 0, time_left);
421 if (rc < 0)
422 {
423 MTLOG_ERROR("socket[%d] send failed, ret[%d][%m]", sock, rc);
424 ret = -2;
425 goto EXIT_LABEL;
426 }
427
428 ret = 0;
429
430EXIT_LABEL:
431
432 if (sock >= 0)
433 ::close(sock);
434
435 return ret;
436}
437
438int mt_tcpsendrcv_ex(struct sockaddr_in* dst, void* pkg, int len, void* rcv_buf, int* buf_size, int timeout, MtFuncTcpMsgLen func, MT_TCP_CONN_TYPE type)
439{

Callers 1

mt_tcpsendrcv_exFunction · 0.85

Calls 5

mt_tcp_create_sockFunction · 0.85
GetLastClockMethod · 0.80
connectFunction · 0.70
sendFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected