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

Function mt_tcpsend

adapter/micro_thread/mt_api.cpp:334–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334int mt_tcpsend(struct sockaddr_in* dst, void* pkg, int len, int timeout)
335{
336 if (!dst || !pkg || len<1)
337 {
338 MTLOG_ERROR("input params invalid, dst[%p], pkg[%p], len[%d]", dst, pkg, len);
339 return -10;
340 }
341
342 int ret = 0, rc = 0;
343 int addr_len = sizeof(struct sockaddr_in);
344 utime64_t start_ms = MtFrame::Instance()->GetLastClock();
345 utime64_t cost_time = 0;
346 int time_left = timeout;
347
348 int sock = -1;
349 TcpKeepConn* conn = mt_tcp_get_keep_conn(dst, sock);
350 if ((conn == NULL) || (sock < 0))
351 {
352 MTLOG_ERROR("socket[%d] get conn failed, ret[%m]", sock);
353 ret = -1;
354 goto EXIT_LABEL;
355 }
356
357 rc = MtFrame::connect(sock, (struct sockaddr *)dst, addr_len, time_left);
358 if (rc < 0)
359 {
360 MTLOG_ERROR("socket[%d] connect failed, ret[%d][%m]", sock, rc);
361 ret = -4;
362 goto EXIT_LABEL;
363 }
364
365 cost_time = MtFrame::Instance()->GetLastClock() - start_ms;
366 time_left = (timeout > (int)cost_time) ? (timeout - (int)cost_time) : 0;
367 rc = MtFrame::send(sock, pkg, len, 0, time_left);
368 if (rc < 0)
369 {
370 MTLOG_ERROR("socket[%d] send failed, ret[%d][%m]", sock, rc);
371 ret = -2;
372 goto EXIT_LABEL;
373 }
374
375 ret = 0;
376
377EXIT_LABEL:
378
379 if (conn != NULL)
380 {
381 ConnectionMgr::Instance()->FreeConnection(conn, (ret < 0));
382 }
383
384 return ret;
385}
386
387int mt_tcpsend_short(struct sockaddr_in* dst, void* pkg, int len, int timeout)
388{

Callers 1

mt_tcpsendrcv_exFunction · 0.85

Calls 5

mt_tcp_get_keep_connFunction · 0.85
GetLastClockMethod · 0.80
FreeConnectionMethod · 0.80
connectFunction · 0.70
sendFunction · 0.70

Tested by

no test coverage detected