Changeset 313 for trunk/src/sh_tools.c
- Timestamp:
- Mar 11, 2011, 8:04:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_tools.c
r295 r313 574 574 { 575 575 if ( 0 == sl_strncmp(check_cache->address, 576 address, sl_strlen(address)) )576 address, sl_strlen(address)) ) 577 577 { 578 578 memcpy (&sinr, &((check_cache->saddr).sin), sizeof(struct sockaddr_in)); … … 778 778 while (check_cache && check_cache->address) 779 779 { 780 if ( 0 == sl_strncmp(check_cache->address, 781 address, sl_strlen(address))) 780 if ( 0 == sl_strcmp(check_cache->address, address) ) 782 781 { 783 782 memcpy (&ss, &(check_cache->saddr), sizeof(struct sh_sockaddr)); … … 787 786 sin = &(ss.sin); 788 787 sin->sin_port = htons (port); 788 cached = 1; 789 break; 789 790 case AF_INET6: 790 791 sin6 = &(ss.sin6); 791 792 sin6->sin6_port = htons (port); 793 cached = 1; 794 break; 795 default: 796 break; 792 797 } 793 cached = 1;794 798 break; 795 799 } … … 814 818 sl_strlcat(errmsg, address, errsiz); 815 819 } 816 817 820 821 818 822 if (fail != (-1)) 819 823 { … … 853 857 hints.ai_flags |= AI_CANONNAME; 854 858 #endif 859 hints.ai_family = AF_UNSPEC; 855 860 hints.ai_socktype = SOCK_STREAM; 856 861 sl_snprintf(sport, sizeof(sport), "%d", port); … … 923 928 while (p != NULL) 924 929 { 925 fd = socket(p->ai_family, p->ai_socktype, 926 p->ai_protocol); 927 928 if (fd != (-1)) 930 if ( (SOCK_STREAM == p->ai_socktype) && 931 ((p->ai_family == AF_INET) || (p->ai_family == AF_INET6)) ) 929 932 { 930 if (retry_connect(FIL__, __LINE__, fd, 931 p->ai_addr, p->ai_addrlen) >= 0) 933 934 fd = socket(p->ai_family, SOCK_STREAM, 0); 935 936 if (fd != (-1)) 932 937 { 933 /* put it into the cache 934 */ 935 check_cache = SH_ALLOC(sizeof(sin_cache)); 936 check_cache->address = SH_ALLOC(sl_strlen(address) + 1); 937 sl_strlcpy (check_cache->address, address, sl_strlen(address) + 1); 938 939 sh_ipvx_save(&(check_cache->saddr), p->ai_family, p->ai_addr); 940 941 ++cached_addr; 942 943 if (conn_cache) 938 if (retry_connect(FIL__, __LINE__, fd, 939 p->ai_addr, p->ai_addrlen) >= 0) 944 940 { 945 if (conn_cache->next) 946 check_cache->next = conn_cache->next; 941 /* put it into the cache 942 */ 943 check_cache = SH_ALLOC(sizeof(sin_cache)); 944 check_cache->address = SH_ALLOC(sl_strlen(address) + 1); 945 sl_strlcpy (check_cache->address, address, sl_strlen(address) + 1); 946 947 sh_ipvx_save(&(check_cache->saddr), p->ai_family, p->ai_addr); 948 949 ++cached_addr; 950 951 if (conn_cache) 952 { 953 if (conn_cache->next) 954 check_cache->next = conn_cache->next; 955 else 956 check_cache->next = NULL; 957 conn_cache->next = check_cache; 958 } 947 959 else 948 check_cache->next = NULL; 949 conn_cache->next = check_cache; 960 { 961 check_cache->next = NULL; 962 conn_cache = check_cache; 963 } 964 965 freeaddrinfo (ai); 966 goto end; 950 967 } 951 else 952 { 953 check_cache->next = NULL; 954 conn_cache = check_cache; 955 } 956 957 freeaddrinfo (ai); 958 goto end; 968 status = errno; 969 sl_close_fd(FIL__, __LINE__, fd); 959 970 } 960 status = errno; 961 sl_close_fd(FIL__, __LINE__, fd); 962 } 963 else 964 { 965 status = errno; 971 else 972 { 973 status = errno; 974 } 966 975 } 967 976 p = p->ai_next;
Note:
See TracChangeset
for help on using the changeset viewer.