Fossil

Check-in [3842742871]
Login

Check-in [3842742871]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use IPv6 when available for "fossil sync".
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | ipv6-sync
Files: files | file ages | folders
SHA1: 3842742871f6b265c6027379dd33d3d228c039cd
User & Date: drh 2015-01-23 01:58:29.564
Context
2015-01-23
02:05
Use IPv6 for "fossil sync" when available. ... (check-in: 1dbd4d0d0b user: drh tags: trunk)
01:58
Use IPv6 when available for "fossil sync". ... (Closed-Leaf check-in: 3842742871 user: drh tags: ipv6-sync)
2015-01-22
23:45
Enhance the table sorting javascript to support initial reverse-order sorting. Add table sorting to the user log. ... (check-in: 0cdec7d290 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/http_socket.c.
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

/*
** There can only be a single socket connection open at a time.
** State information about that socket is stored in the following
** local variables:
*/
static int socketIsInit = 0;    /* True after global initialization */
static int addrIsInit = 0;      /* True once addr is initialized */
#if defined(_WIN32)
static WSADATA socketInfo;      /* Windows socket initialize data */
#endif
static int iSocket = -1;        /* The socket on which we talk to the server */
static char *socketErrMsg = 0;  /* Text of most recent socket error */









<







43
44
45
46
47
48
49

50
51
52
53
54
55
56

/*
** There can only be a single socket connection open at a time.
** State information about that socket is stored in the following
** local variables:
*/
static int socketIsInit = 0;    /* True after global initialization */

#if defined(_WIN32)
static WSADATA socketInfo;      /* Windows socket initialize data */
#endif
static int iSocket = -1;        /* The socket on which we talk to the server */
static char *socketErrMsg = 0;  /* Text of most recent socket error */


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  if( socketIsInit ){
#if defined(_WIN32)
    WSACleanup();
#endif
    socket_clear_errmsg();
    socketIsInit = 0;
  }
  addrIsInit = 0;
}

/*
** Close the currently open socket.  If no socket is open, this routine
** is a no-op.
*/
void socket_close(void){







<







103
104
105
106
107
108
109

110
111
112
113
114
115
116
  if( socketIsInit ){
#if defined(_WIN32)
    WSACleanup();
#endif
    socket_clear_errmsg();
    socketIsInit = 0;
  }

}

/*
** Close the currently open socket.  If no socket is open, this routine
** is a no-op.
*/
void socket_close(void){
132
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
**
**    pUrlDAta->name       Name of the server.  Ex: www.fossil-scm.org
**    pUrlDAta->port       TCP/IP port to use.  Ex: 80
**
** Return the number of errors.
*/
int socket_open(UrlData *pUrlData){


  static struct sockaddr_in addr;  /* The server address */



  socket_global_init();
  if( !addrIsInit ){
    memset(&addr, 0, sizeof(addr));

    addr.sin_family = AF_INET;


    addr.sin_port = htons(pUrlData->port);
    *(int*)&addr.sin_addr = inet_addr(pUrlData->name);
    if( -1 == *(int*)&addr.sin_addr ){
#ifndef FOSSIL_STATIC_LINK
      struct hostent *pHost;
      pHost = gethostbyname(pUrlData->name);
      if( pHost!=0 ){
        memcpy(&addr.sin_addr,pHost->h_addr_list[0],pHost->h_length);
      }else
#endif
      {
        socket_set_errmsg("can't resolve host name: %s", pUrlData->name);
        return 1;
      }
    }



    addrIsInit = 1;


    /* Set the Global.zIpAddr variable to the server we are talking to.
    ** This is used to populate the ipaddr column of the rcvfrom table,
    ** if any files are received from the server.
    */
    g.zIpAddr = mprintf("%s", inet_ntoa(addr.sin_addr));
  }
  iSocket = socket(AF_INET,SOCK_STREAM,0);
  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", pUrlData->name,
                      pUrlData->port);

    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;







>
>
|
>
>


<
|
>
|
>
>
|
<
<
<
<
|
|
<
<
<
<
|
|
|
<
>
>
>
|
>
|
<
<
<
<
|
<
|


|
>

|


>
|
<




>
>
>
|







130
131
132
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
**
**    pUrlDAta->name       Name of the server.  Ex: www.fossil-scm.org
**    pUrlDAta->port       TCP/IP port to use.  Ex: 80
**
** Return the number of errors.
*/
int socket_open(UrlData *pUrlData){
  int rc = 0;
  struct addrinfo *ai = 0;
  struct addrinfo hints;
  char zPort[30];
  char zRemote[NI_MAXHOST];

  socket_global_init();

  memset(&hints, 0, sizeof(struct addrinfo));
  assert( iSocket<0 );
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  sqlite3_snprintf(sizeof(zPort),zPort,"%d", pUrlData->port);




  rc = getaddrinfo(pUrlData->name, zPort, &hints, &ai);
  if( rc ){




    socket_set_errmsg("getaddrinfo() fails: %s", gai_strerror(rc));
    goto end_socket_open;
  }

  rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, zRemote, sizeof(zRemote),
                   0, 0, NI_NUMERICHOST);
  if( rc ){
    socket_set_errmsg("getnameinfo() failed: %s", gai_strerror(rc));
    goto end_socket_open;
  }




  g.zIpAddr = mprintf("%s", zRemote);

  iSocket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
  if( iSocket<0 ){
    socket_set_errmsg("cannot create a socket");
    rc = 1;
    goto end_socket_open;
  }
  if( connect(iSocket,ai->ai_addr,ai->ai_addrlen)<0 ){
    socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
                      pUrlData->port);
    rc = 1;
    goto end_socket_open;

  }
#if !defined(_WIN32)
  signal(SIGPIPE, SIG_IGN);
#endif
end_socket_open:
  if( rc && iSocket>=0 ) socket_close();
  if( ai ) freeaddrinfo(ai);
  return rc;
}

/*
** Send content out over the open socket connection.
*/
size_t socket_send(void *NotUsed, void *pContent, size_t N){
  size_t sent;
Changes to src/xfer.c.
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
     fossil_warning("*** time skew *** server is slow by %s",
                    db_timespan_name(-rSkew));
     g.clockSkewSeen = 1;
  }

  fossil_force_newline();
  fossil_print(
     "%s finished with %lld bytes sent, %lld bytes received\n",
     zOpType, nSent, nRcvd);
  transport_close(&g.url);
  transport_global_shutdown(&g.url);
  if( nErr && go==2 ){
    db_multi_exec("DROP TABLE onremote");
    manifest_crosslink_end(MC_PERMIT_HOOKS);
    content_enable_dephantomize(1);
    db_end_transaction(0);







|
|







1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
     fossil_warning("*** time skew *** server is slow by %s",
                    db_timespan_name(-rSkew));
     g.clockSkewSeen = 1;
  }

  fossil_force_newline();
  fossil_print(
     "Total bytes sent: %lld  received: %lld  ip: %s\n",
      nSent, nRcvd, g.zIpAddr);
  transport_close(&g.url);
  transport_global_shutdown(&g.url);
  if( nErr && go==2 ){
    db_multi_exec("DROP TABLE onremote");
    manifest_crosslink_end(MC_PERMIT_HOOKS);
    content_enable_dephantomize(1);
    db_end_transaction(0);