MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / at_socket

Function at_socket

components/net/at/at_socket/at_socket.c:504–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

502static void at_closed_notice_cb(struct at_socket *sock, at_socket_evt_t event, const char *buff, size_t bfsz);
503
504int at_socket(int domain, int type, int protocol)
505{
506 struct at_socket *sock = RT_NULL;
507 enum at_socket_type socket_type;
508
509 /* check socket family protocol */
510 if(domain != AF_INET && domain != AF_AT)
511 {
512 rt_set_errno(EAFNOSUPPORT);
513 return -1;
514 }
515
516 /*TODO check protocol*/
517
518 switch(type)
519 {
520 case SOCK_STREAM:
521 socket_type = AT_SOCKET_TCP;
522 break;
523
524 case SOCK_DGRAM:
525 socket_type = AT_SOCKET_UDP;
526 break;
527
528 default :
529 LOG_E("Don't support socket type (%d)!", type);
530 rt_set_errno(EPROTOTYPE);
531 return -1;
532 }
533
534 /* allocate and initialize a new AT socket */
535 sock = alloc_socket(socket_type);
536 if (sock == RT_NULL)
537 {
538 LOG_E("Failed to allocate socket");
539 rt_set_errno(EIO);
540 return -1;
541 }
542 sock->type = socket_type;
543 sock->state = AT_SOCKET_OPEN;
544
545 /* set AT socket receive data callback function */
546 sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb);
547 sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb);
548#ifdef AT_USING_SOCKET_SERVER
549 sock->ops->at_set_event_cb(AT_SOCKET_EVT_CONNECTED, at_connect_notice_cb);
550#endif
551
552 return sock->socket;
553}
554
555int at_closesocket(int socket)
556{

Callers 1

at_connect_notice_cbFunction · 0.70

Calls 2

rt_set_errnoFunction · 0.85
alloc_socketFunction · 0.70

Tested by

no test coverage detected