Fossil

Diff
Login

Differences From Artifact [b954ec7a36]:

To Artifact [a2c45f3370]:


133
134
135
136
137
138
139














































140
141
142
143
144
145
146
**
**    g.urlName       Name of the server.  Ex: www.fossil-scm.org
**    g.urlPort       TCP/IP port to use.  Ex: 80
**
** Return the number of errors.
*/
int socket_open(void){














































  static struct sockaddr_in addr;  /* The server address */
  static int addrIsInit = 0;       /* True once addr is initialized */

  socket_global_init();
  if( !addrIsInit ){
    addr.sin_family = AF_INET;
    addr.sin_port = htons(g.urlPort);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
**
**    g.urlName       Name of the server.  Ex: www.fossil-scm.org
**    g.urlPort       TCP/IP port to use.  Ex: 80
**
** Return the number of errors.
*/
int socket_open(void){
  int error = 0;
#ifdef HAVE_GETADDRINFO
  struct addrinfo hints;
  struct addrinfo* res;
  struct addrinfo* i;
  char ip[INET6_ADDRSTRLEN];
  void* addr;

  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_flags = AI_ADDRCONFIG;
#ifdef WITH_IPV6
  hints.ai_family = PF_UNSPEC;
#else
  hints.ai_family = PF_INET;
#endif
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  if(getaddrinfo(g.urlName, NULL, &hints, &res)) {
    socket_set_errmsg("can't resolve host name: %s", g.urlName);
    return 1;
  }
  for(i = res; i; i = i->ai_next) {
    iSocket = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
    if(iSocket < 0) {
      continue;
    }
    if(i->ai_family == AF_INET) {
      ((struct sockaddr_in*)i->ai_addr)->sin_port = htons(g.urlPort);
    } else if(i->ai_family == AF_INET6) {
      ((struct sockaddr_in6*)i->ai_addr)->sin6_port = htons(g.urlPort);
    }
    if(connect(iSocket, i->ai_addr, i->ai_addrlen) < 0) {
      close(iSocket);
      iSocket = -1;
      continue;
    }
	if(!getnameinfo(i->ai_addr, i->ai_addrlen, ip, sizeof(ip),
					NULL, 0, NI_NUMERICHOST))
		g.zIpAddr = mprintf("%s", ip);
  }
  if(iSocket == -1) {
    socket_set_errmsg("cannot connect to host %s:%d", g.urlName, g.urlPort);
    error = 1;
  }
  freeaddrinfo(res);
#else
  static struct sockaddr_in addr;  /* The server address */
  static int addrIsInit = 0;       /* True once addr is initialized */

  socket_global_init();
  if( !addrIsInit ){
    addr.sin_family = AF_INET;
    addr.sin_port = htons(g.urlPort);
170
171
172
173
174
175
176
177
178

179

180
181
182
183
184
185
186
187
188
189
  if( iSocket<0 ){
    socket_set_errmsg("cannot create a socket");
    return 1;
  }
  if( connect(iSocket,(struct sockaddr*)&addr,sizeof(addr))<0 ){
    socket_set_errmsg("cannot connect to host %s:%d", g.urlName, g.urlPort);
    socket_close();
    return 1;
  }

#if !defined(_WIN32)

  signal(SIGPIPE, SIG_IGN);
#endif
  return 0;
}

/*
** Send content out over the open socket connection.
*/
size_t socket_send(void *NotUsed, void *pContent, size_t N){
  size_t sent;







|

>

>
|

|







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  if( iSocket<0 ){
    socket_set_errmsg("cannot create a socket");
    return 1;
  }
  if( connect(iSocket,(struct sockaddr*)&addr,sizeof(addr))<0 ){
    socket_set_errmsg("cannot connect to host %s:%d", g.urlName, g.urlPort);
    socket_close();
    error = 1;
  }
#endif
#if !defined(_WIN32)
  if(!error)
    signal(SIGPIPE, SIG_IGN);
#endif
  return error;
}

/*
** Send content out over the open socket connection.
*/
size_t socket_send(void *NotUsed, void *pContent, size_t N){
  size_t sent;