Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support none-blocking DNS resolve. #2112

Closed
Tracked by #2188
JalySN opened this issue Dec 26, 2020 · 2 comments
Closed
Tracked by #2188

Support none-blocking DNS resolve. #2112

JalySN opened this issue Dec 26, 2020 · 2 comments
Assignees
Labels
EnglishNative This issue is conveyed exclusively in English. Feature It's a new feature.
Milestone

Comments

@JalySN
Copy link

JalySN commented Dec 26, 2020

srs_tcp_connect is a modification I made, what do you think, esteemed author?

#include "res.c"
srs_error_t srs_tcp_connect(string server, int port, srs_utime_t tm, srs_netfd_t* pstfd)
{
    st_utime_t timeout = ST_UTIME_NO_TIMEOUT;
    if (tm != SRS_UTIME_NO_TIMEOUT) {
        timeout = tm;
    }
    
    *pstfd = NULL;
    srs_netfd_t stfd = NULL;
/*
    char sport[8];
    snprintf(sport, sizeof(sport), "%d", port);
    
    addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family   = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    
    addrinfo* r  = NULL;
    SrsAutoFree(addrinfo, r);
    if(getaddrinfo(server.c_str(), sport, (const addrinfo*)&hints, &r)) {
        return srs_error_new(ERROR_SYSTEM_IP_INVALID, "get address info");
    }
    int sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
    if(sock == -1){
        return srs_error_new(ERROR_SOCKET_CREATE, "create socket");
    }
*/
    struct in_addr addr;
    if (dns_getaddr(server.c_str(), &addr, timeout) < 0) {
        return srs_error_new(ERROR_SYSTEM_IP_INVALID, "get address info");
    }
    uint32_t uiIP;
    memcpy(&uiIP, &addr, 4);
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if(sock == -1) {
        return srs_error_new(ERROR_SOCKET_CREATE, "create socket");
    }
    stfd = st_netfd_open_socket(sock);
    if(stfd == NULL){
        ::close(sock);
        return srs_error_new(ERROR_ST_OPEN_SOCKET, "open socket");
    }
    struct sockaddr_in address;
    memset(&address, 0, sizeof(address));
    address.sin_family      = AF_INET;
    address.sin_addr.s_addr = uiIP;
    address.sin_port        = htons(port);
    if (st_connect((st_netfd_t)stfd, (struct sockaddr*)&address, sizeof(address), timeout) == -1){
        srs_close_stfd(stfd);
        return srs_error_new(ERROR_ST_CONNECT, "connect to %s:%d", server.c_str(), port);
    }
    
    *pstfd = stfd;
    return srs_success;
}
@winlinvip
Copy link
Member

winlinvip commented Jan 2, 2021

Yes, you're right, would you like to submit a patch?

@winlinvip winlinvip changed the title dns解析block问题,可参考state-thread的example?/trunk/3rdparty/st-srs/examples/lookupdns.c 实现DNS协议,避免系统解析block的问题 Jan 2, 2021
@winlinvip
Copy link
Member

winlinvip commented Jan 2, 2021

It would be best if it could equivalently replace the system's getaddrinfo function, as it would be more convenient to use and is used in many places.

@winlinvip winlinvip added this to the SRS 5.0 release milestone Aug 25, 2021
@winlinvip winlinvip added the Feature It's a new feature. label Jan 17, 2022
@winlinvip winlinvip changed the title 实现DNS协议,避免系统解析block的问题 Support none-blocking DNS resolve. 实现DNS协议,避免系统解析block的问题 Jan 2, 2023
@winlinvip winlinvip modified the milestones: 5.0, 6.0 Jan 2, 2023
@winlinvip winlinvip changed the title Support none-blocking DNS resolve. 实现DNS协议,避免系统解析block的问题 Support none-blocking DNS resolve. Jul 18, 2023
@ossrs ossrs locked and limited conversation to collaborators Jul 18, 2023
@winlinvip winlinvip converted this issue into discussion #3649 Jul 18, 2023
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jul 29, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
EnglishNative This issue is conveyed exclusively in English. Feature It's a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants