- Timestamp:
- 08/01/10 11:25:57 (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r2883 r2886 1172 1172 extern void * start_cardreader(void *); 1173 1173 extern void reader_card_info(struct s_reader * reader); 1174 extern int hostResolve( );1174 extern int hostResolve(int ridx); 1175 1175 extern int network_tcp_connection_open(); 1176 1176 extern void network_tcp_connection_close(struct s_reader * reader, int); -
trunk/oscam-http.c
r2882 r2886 2187 2187 ok = 1; 2188 2188 } else { 2189 pthread_mutex_lock(&gethostbyname_lock); //gethostbyname ist NOT threadsafe! So we need a mutex-lock!2190 2189 struct hostent *rht; 2191 2190 struct sockaddr_in udp_sa; … … 2197 2196 ok = 1; 2198 2197 } 2199 pthread_mutex_unlock(&gethostbyname_lock); //gethostbyname ist NOT threadsafe! So we need a mutex-lock!2200 2198 } 2201 2199 } -
trunk/oscam-reader.c
r2837 r2886 139 139 140 140 // according to documentation getaddrinfo() is thread safe 141 int hostResolve( )141 int hostResolve(int ridx) 142 142 { 143 143 struct addrinfo hints, *res = NULL; 144 144 145 int cs_idx = reader[ridx].cs_idx; 146 145 147 memset(&hints, 0, sizeof(hints)); 146 148 hints.ai_socktype = SOCK_STREAM; … … 170 172 cs_log("connecting to %s", reader[ridx].device); 171 173 172 if (!hostResolve( ))174 if (!hostResolve(ridx)) 173 175 return -1; 174 176 -
trunk/oscam.c
r2884 r2886 27 27 char cs_confdir[128]=CS_CONFDIR; 28 28 uchar mbuf[1024]; // global buffer 29 pthread_mutex_t gethostbyname_lock; //gethostbyname ist NOT threadsafe! So we need a mutex-lock!30 29 ECM_REQUEST *ecmtask; 31 30 #ifdef CS_ANTICASC … … 924 923 strcpy(client[0].usr, "root"); 925 924 926 pthread_mutex_init(&gethostbyname_lock, NULL); //gethostbyname ist NOT threadsafe! So we need a mutex-lock!927 925 init_stat(); 928 926 … … 1056 1054 while (1) 1057 1055 { 1058 struct hostent *rht;1056 struct addrinfo hints, *res = NULL; 1059 1057 struct s_auth *account; 1060 struct sockaddr_in udp_sa; 1061 1058 1062 1059 for (account=cfg->account; account; account=account->next) 1063 1060 if (account->dyndns[0]) 1064 1061 { 1065 pthread_mutex_lock(&gethostbyname_lock); //gethostbyname ist NOT threadsafe! So we need a mutex-lock! 1066 rht=gethostbyname((const char *)account->dyndns); 1067 if (rht) 1068 { 1069 memcpy(&udp_sa.sin_addr, rht->h_addr, sizeof(udp_sa.sin_addr)); 1070 account->dynip=cs_inet_order(udp_sa.sin_addr.s_addr); 1062 memset(&hints, 0, sizeof(hints)); 1063 hints.ai_socktype = SOCK_STREAM; 1064 hints.ai_family = AF_INET; 1065 hints.ai_protocol = IPPROTO_TCP; 1066 1067 int err = getaddrinfo((const char*)account->dyndns, NULL, &hints, &res); 1068 if (err != 0 || !res || !res->ai_addr) { 1069 cs_log("can't resolve %s, error: %s", account->dyndns, err ? gai_strerror(err) : "unknown"); 1070 } 1071 else { 1072 account->dynip=cs_inet_order(((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr); 1071 1073 } 1072 else 1073 cs_log("can't resolve hostname %s (user: %s)", account->dyndns, account->usr); 1074 client[cs_idx].last=time((time_t)0); 1075 pthread_mutex_unlock(&gethostbyname_lock); //gethostbyname ist NOT threadsafe! So we need a mutex-lock! 1074 if (res) freeaddrinfo(res); 1076 1075 } 1077 1076 sleep(cfg->resolvedelay); … … 2834 2833 } 2835 2834 2835 void cs_resolve() 2836 { 2837 int i; 2838 for (i=0; i<CS_MAXREADER; i++) 2839 if ((reader[i].cs_idx) && (reader[i].typ & R_IS_NETWORK) && (reader[i].typ!=R_CONSTCW)) 2840 hostResolve(i); 2841 } 2842 2843 static void loop_resolver() 2844 { 2845 cs_sleepms(1000); // wait for reader 2846 while(1) 2847 { 2848 cs_resolve(); 2849 cs_sleepms(1000*cfg->resolvedelay); 2850 } 2851 } 2852 2853 2836 2854 int main (int argc, char *argv[]) 2837 2855 {
Note:
See TracChangeset
for help on using the changeset viewer.