Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

io.c File Reference

Socket and pipe IO utilities used in rsync. More...

Go to the source code of this file.

Functions

void read_loop (int fd, char *buf, size_t len)
 Continue trying to read len bytes - don't return until len has been read. More...

void check_timeout (void)
void io_set_error_fd (int fd)
 Setup the fd used to propagate errors. More...

void read_error_fd (void)
 Read some data from the error fd and write it to the write log code. More...

void whine_about_eof (void)
 It's almost always an error to get an EOF when we're trying to read from the network, because the protocol is self-terminating. More...

void die_from_readerr (int err)
int read_timeout (int fd, char *buf, size_t len)
 Read from a socket with IO timeout. More...

int read_unbuffered (int fd, char *buf, size_t len)
 Read from the file descriptor handling multiplexing - return number of bytes read. More...

void readfd (int fd, char *buffer, size_t N)
 Do a buffered read from fd. More...

int32 read_int (int f)
int64 read_longint (int f)
void read_buf (int f, char *buf, size_t len)
void read_sbuf (int f, char *buf, size_t len)
unsigned char read_byte (int f)
void sleep_for_bwlimit (int bytes_written)
 Sleep after writing to limit I/O bandwidth usage. More...

void writefd_unbuffered (int fd, char *buf, size_t len)
 Write len bytes to the file descriptor fd. More...

void io_start_buffering (int fd)
void mplex_write (int fd, enum logcode code, char *buf, size_t len)
 Write an message to a multiplexed stream. More...

void io_flush (void)
void io_end_buffering (void)
void writefd (int fd, char *buf, size_t len)
void write_int (int f, int32 x)
void write_int_named (int f, int32 x, const char *phase)
void write_longint (int f, int64 x)
void write_buf (int f, char *buf, size_t len)
void write_sbuf (int f, char *buf)
 Write a string to the connection. More...

void write_byte (int f, unsigned char c)
int read_line (int f, char *buf, size_t maxlen)
 Read a line of up to maxlen characters into buf. More...

void io_printf (int fd, const char *format,...)
void io_start_multiplex_out (int fd)
 Setup for multiplexing an error stream with the data stream. More...

void io_start_multiplex_in (int fd)
 Setup for multiplexing an error stream with the data stream. More...

int io_multiplex_write (enum logcode code, char *buf, size_t len)
 Write an message to the multiplexed error stream. More...

void io_multiplexing_close (void)
 Stop output multiplexing. More...


Variables

int io_multiplexing_out
int io_multiplexing_in
int multiplex_in_fd
int multiplex_out_fd
time_t last_io
int no_flush
int bwlimit
int verbose
int io_timeout
stats stats
const char phase_unknown [] = "unknown"
const char * io_write_phase = phase_unknown
 The connection might be dropped at some point; perhaps because the remote instance crashed. More...

const char * io_read_phase = phase_unknown
int kludge_around_eof = False
 Ignore EOF errors while reading a module listing if the remote version is 24 or less. More...

int io_error_fd = -1
char * io_buffer
int io_buffer_count


Detailed Description

Socket and pipe IO utilities used in rsync.

rsync provides its own multiplexing system, which is used to send stderr and stdout over a single socket. We need this because stdout normally carries the binary data stream, and stderr all our error messages.

For historical reasons this is off during the start of the connection, but it's switched on quite early using io_start_multiplex_out() and io_start_multiplex_in().

Definition in file io.c.


Function Documentation

void read_loop int    fd,
char *    buf,
size_t    len
[static]
 

Continue trying to read len bytes - don't return until len has been read.

Definition at line 267 of file io.c.

References read_timeout().

Referenced by read_error_fd(), and read_unbuffered().

00268 {
00269         while (len) {
00270                 int n = read_timeout(fd, buf, len);
00271 
00272                 buf += n;
00273                 len -= n;
00274         }
00275 }

void check_timeout void    [static]
 

Definition at line 82 of file io.c.

References am_daemon, err_list_push(), FERROR, io_timeout, last_io, and rprintf().

Referenced by read_timeout(), and writefd_unbuffered().

00083 {
00084         extern int am_server, am_daemon;
00085         time_t t;
00086 
00087         err_list_push();
00088         
00089         if (!io_timeout) return;
00090 
00091         if (!last_io) {
00092                 last_io = time(NULL);
00093                 return;
00094         }
00095 
00096         t = time(NULL);
00097 
00098         if (last_io && io_timeout && (t-last_io) >= io_timeout) {
00099                 if (!am_server && !am_daemon) {
00100                         rprintf(FERROR,"io timeout after %d seconds - exiting\n", 
00101                                 (int)(t-last_io));
00102                 }
00103                 exit_cleanup(RERR_TIMEOUT);
00104         }
00105 }

void io_set_error_fd int    fd
 

Setup the fd used to propagate errors.

Definition at line 108 of file io.c.

References io_error_fd.

Referenced by do_recv().

00109 {
00110         io_error_fd = fd;
00111 }

void read_error_fd void    [static]
 

Read some data from the error fd and write it to the write log code.

Definition at line 114 of file io.c.

References io_error_fd, logcode, read_loop(), rwrite(), and tag.

Referenced by read_timeout(), and writefd_unbuffered().

00115 {
00116         char buf[200];
00117         size_t n;
00118         int fd = io_error_fd;
00119         int tag, len;
00120 
00121         /* io_error_fd is temporarily disabled -- is this meant to
00122          * prevent indefinite recursion? */
00123         io_error_fd = -1;
00124 
00125         read_loop(fd, buf, 4);
00126         tag = IVAL(buf, 0);
00127 
00128         len = tag & 0xFFFFFF;
00129         tag = tag >> 24;
00130         tag -= MPLEX_BASE;
00131 
00132         while (len) {
00133                 n = len;
00134                 if (n > (sizeof(buf)-1))
00135                         n = sizeof(buf)-1;
00136                 read_loop(fd, buf, n);
00137                 rwrite((enum logcode)tag, buf, n);
00138                 len -= n;
00139         }
00140 
00141         io_error_fd = fd;
00142 }

void whine_about_eof void    [static]
 

It's almost always an error to get an EOF when we're trying to read from the network, because the protocol is self-terminating.

However, there is one unfortunate cases where it is not, which is rsync <2.4.6 sending a list of modules on a server, since the list is terminated by closing the socket. So, for the section of the program where that is a problem (start_socket_client), kludge_around_eof is True and we just exit.

Definition at line 155 of file io.c.

References FERROR, rprintf(), and stats::total_read.

Referenced by read_timeout().

00156 {
00157         if (kludge_around_eof)
00158                 exit_cleanup (0);
00159         else {
00160                 rprintf (FERROR,
00161                          "%s: connection unexpectedly closed "
00162                          "(%.0f bytes read so far)\n",
00163                          RSYNC_NAME, (double)stats.total_read);
00164         
00165                 exit_cleanup (RERR_STREAMIO);
00166         }
00167 }

void die_from_readerr int    err [static]
 

Definition at line 170 of file io.c.

References FERROR, io_multiplexing_close(), and rprintf().

Referenced by read_timeout().

00171 {
00172         /* this prevents us trying to write errors on a dead socket */
00173         io_multiplexing_close();
00174                                 
00175         rprintf(FERROR, "%s: read error: %s\n",
00176                 RSYNC_NAME, strerror (err));
00177         exit_cleanup(RERR_STREAMIO);
00178 }

int read_timeout int    fd,
char *    buf,
size_t    len
[static]
 

Read from a socket with IO timeout.

return the number of bytes read. If no bytes can be read then exit, never return a number <= 0.

TODO: If the remote shell connection fails, then current versions actually report an "unexpected EOF" error here. Since it's a fairly common mistake to try to use rsh when ssh is required, we should trap that: if we fail to read any data at all, we should give a better explanation. We can tell whether the connection has started by looking e.g. at whether the remote version is known yet.

Definition at line 192 of file io.c.

References check_timeout(), die_from_readerr(), io_error_fd, io_flush(), io_timeout, last_io, read_error_fd(), and whine_about_eof().

Referenced by read_loop(), and read_unbuffered().

00193 {
00194         int n, ret=0;
00195 
00196         io_flush();
00197 
00198         while (ret == 0) {
00199                 /* until we manage to read *something* */
00200                 fd_set fds;
00201                 struct timeval tv;
00202                 int fd_count = fd+1;
00203                 int count;
00204 
00205                 FD_ZERO(&fds);
00206                 FD_SET(fd, &fds);
00207                 if (io_error_fd != -1) {
00208                         FD_SET(io_error_fd, &fds);
00209                         if (io_error_fd > fd) fd_count = io_error_fd+1;
00210                 }
00211 
00212                 tv.tv_sec = io_timeout?io_timeout:SELECT_TIMEOUT;
00213                 tv.tv_usec = 0;
00214 
00215                 errno = 0;
00216 
00217                 count = select(fd_count, &fds, NULL, NULL, &tv);
00218 
00219                 if (count == 0) {
00220                         check_timeout();
00221                 }
00222 
00223                 if (count <= 0) {
00224                         if (errno == EBADF) {
00225                                 exit_cleanup(RERR_SOCKETIO);
00226                         }
00227                         continue;
00228                 }
00229 
00230                 if (io_error_fd != -1 && FD_ISSET(io_error_fd, &fds)) {
00231                         read_error_fd();
00232                 }
00233 
00234                 if (!FD_ISSET(fd, &fds)) continue;
00235 
00236                 n = read(fd, buf, len);
00237 
00238                 if (n > 0) {
00239                         buf += n;
00240                         len -= n;
00241                         ret += n;
00242                         if (io_timeout)
00243                                 last_io = time(NULL);
00244                         continue;
00245                 } else if (n == 0) {
00246                         whine_about_eof ();
00247                         return -1; /* doesn't return */
00248                 } else if (n == -1) {
00249                         if (errno == EINTR || errno == EWOULDBLOCK ||
00250                             errno == EAGAIN) 
00251                                 continue;
00252                         else
00253                                 die_from_readerr (errno);
00254                 }
00255         }
00256 
00257         return ret;
00258 }

int read_unbuffered int    fd,
char *    buf,
size_t    len
[static]
 

Read from the file descriptor handling multiplexing - return number of bytes read.

Never returns <= 0.

Definition at line 284 of file io.c.

References FERROR, FINFO, io_multiplexing_in, logcode, multiplex_in_fd, read_loop(), read_timeout(), rprintf(), and tag.

Referenced by readfd().

00285 {
00286         static size_t remaining;
00287         int tag, ret = 0;
00288         char line[1024];
00289 
00290         if (!io_multiplexing_in || fd != multiplex_in_fd)
00291                 return read_timeout(fd, buf, len);
00292 
00293         while (ret == 0) {
00294                 if (remaining) {
00295                         len = MIN(len, remaining);
00296                         read_loop(fd, buf, len);
00297                         remaining -= len;
00298                         ret = len;
00299                         continue;
00300                 }
00301 
00302                 read_loop(fd, line, 4);
00303                 tag = IVAL(line, 0);
00304 
00305                 remaining = tag & 0xFFFFFF;
00306                 tag = tag >> 24;
00307 
00308                 if (tag == MPLEX_BASE)
00309                         continue;
00310 
00311                 tag -= MPLEX_BASE;
00312 
00313                 if (tag != FERROR && tag != FINFO) {
00314                         rprintf(FERROR, "unexpected tag %d\n", tag);
00315                         exit_cleanup(RERR_STREAMIO);
00316                 }
00317 
00318                 if (remaining > sizeof(line) - 1) {
00319                         rprintf(FERROR, "multiplexing overflow %d\n\n",
00320                                 remaining);
00321                         exit_cleanup(RERR_STREAMIO);
00322                 }
00323 
00324                 read_loop(fd, line, remaining);
00325                 line[remaining] = 0;
00326 
00327                 rprintf((enum logcode) tag, "%s", line);
00328                 remaining = 0;
00329         }
00330 
00331         return ret;
00332 }

void readfd int    fd,
char *    buffer,
size_t    N
[static]
 

Do a buffered read from fd.

Don't return until all n bytes have been read. If all n can't be read then exit with an error.

Definition at line 341 of file io.c.

References io_flush(), read_unbuffered(), and stats::total_read.

Referenced by read_buf(), read_int(), and read_longint().

00342 {
00343         int  ret;
00344         size_t total=0;  
00345         
00346         while (total < N) {
00347                 io_flush();
00348 
00349                 ret = read_unbuffered (fd, buffer + total, N-total);
00350                 total += ret;
00351         }
00352 
00353         stats.total_read += total;
00354 }

int32 read_int int    f
 

Definition at line 357 of file io.c.

References readfd().

Referenced by client_run(), do_recv(), do_server_sender(), generate_files(), read_longint(), receive_data(), receive_file_entry(), receive_sums(), recv_deflated_token(), recv_exclude_list(), recv_file_list(), recv_files(), recv_uid_list(), send_files(), setup_protocol(), and simple_recv_token().

00358 {
00359         char b[4];
00360         int32 ret;
00361 
00362         readfd(f,b,4);
00363         ret = IVAL(b,0);
00364         if (ret == (int32)0xffffffff) return -1;
00365         return ret;
00366 }

int64 read_longint int    f
 

Definition at line 368 of file io.c.

References FERROR, read_int(), readfd(), and rprintf().

Referenced by receive_file_entry(), and report().

00369 {
00370         extern int remote_version;
00371         int64 ret;
00372         char b[8];
00373         ret = read_int(f);
00374 
00375         if ((int32)ret != (int32)0xffffffff) {
00376                 return ret;
00377         }
00378 
00379 #ifdef NO_INT64
00380         rprintf(FERROR,"Integer overflow - attempted 64 bit offset\n");
00381         exit_cleanup(RERR_UNSUPPORTED);
00382 #else
00383         if (remote_version >= 16) {
00384                 readfd(f,b,8);
00385                 ret = IVAL(b,0) | (((int64)IVAL(b,4))<<32);
00386         }
00387 #endif
00388 
00389         return ret;
00390 }

void read_buf int    f,
char *    buf,
size_t    len
 

Definition at line 392 of file io.c.

References readfd().

Referenced by read_byte(), read_line(), read_sbuf(), receive_data(), receive_file_entry(), receive_sums(), recv_deflated_token(), and simple_recv_token().

00393 {
00394         readfd(f,buf,len);
00395 }

void read_sbuf int    f,
char *    buf,
size_t    len
 

Definition at line 397 of file io.c.

References read_buf().

Referenced by receive_file_entry(), recv_exclude_list(), and recv_uid_list().

00398 {
00399         read_buf (f,buf,len);
00400         buf[len] = 0;
00401 }

unsigned char read_byte int    f
 

Definition at line 403 of file io.c.

References read_buf().

Referenced by receive_file_entry(), recv_deflated_token(), recv_file_list(), and recv_uid_list().

00404 {
00405         unsigned char c;
00406         read_buf (f, (char *)&c, 1);
00407         return c;
00408 }

void sleep_for_bwlimit int    bytes_written [static]
 

Sleep after writing to limit I/O bandwidth usage.

Todo:
Rather than sleeping after each write, it might be better to use some kind of averaging. The current algorithm seems to always use a bit less bandwidth than specified, because it doesn't make up for slow periods. But arguably this is a feature. In addition, we ought to take the time used to write the data into account.

Definition at line 420 of file io.c.

References bwlimit.

Referenced by writefd_unbuffered().

00421 {
00422         struct timeval tv;
00423 
00424         if (!bwlimit)
00425                 return;
00426 
00427         assert(bytes_written > 0);
00428         assert(bwlimit > 0);
00429         
00430         tv.tv_usec = bytes_written * 1000 / bwlimit;
00431         tv.tv_sec  = tv.tv_usec / 1000000;
00432         tv.tv_usec = tv.tv_usec % 1000000;
00433 
00434         select(0, NULL, NULL, NULL, &tv);
00435 }

void writefd_unbuffered int    fd,
char *    buf,
size_t    len
[static]
 

Write len bytes to the file descriptor fd.

This function underlies the multiplexing system. The body of the application never calls this function directly.

Definition at line 444 of file io.c.

References check_timeout(), err_list_push(), FERROR, io_error_fd, io_multiplexing_close(), io_timeout, io_write_phase, last_io, msleep(), no_flush, read_error_fd(), rprintf(), and sleep_for_bwlimit().

Referenced by io_flush(), mplex_write(), and writefd().

00445 {
00446         size_t total = 0;
00447         fd_set w_fds, r_fds;
00448         int fd_count, count;
00449         struct timeval tv;
00450 
00451         err_list_push();
00452 
00453         no_flush++;
00454 
00455         while (total < len) {
00456                 FD_ZERO(&w_fds);
00457                 FD_ZERO(&r_fds);
00458                 FD_SET(fd,&w_fds);
00459                 fd_count = fd;
00460 
00461                 if (io_error_fd != -1) {
00462                         FD_SET(io_error_fd,&r_fds);
00463                         if (io_error_fd > fd_count) 
00464                                 fd_count = io_error_fd;
00465                 }
00466 
00467                 tv.tv_sec = io_timeout?io_timeout:SELECT_TIMEOUT;
00468                 tv.tv_usec = 0;
00469 
00470                 errno = 0;
00471 
00472                 count = select(fd_count+1,
00473                                io_error_fd != -1?&r_fds:NULL,
00474                                &w_fds,NULL,
00475                                &tv);
00476 
00477                 if (count == 0) {
00478                         check_timeout();
00479                 }
00480 
00481                 if (count <= 0) {
00482                         if (errno == EBADF) {
00483                                 exit_cleanup(RERR_SOCKETIO);
00484                         }
00485                         continue;
00486                 }
00487 
00488                 if (io_error_fd != -1 && FD_ISSET(io_error_fd, &r_fds)) {
00489                         read_error_fd();
00490                 }
00491 
00492                 if (FD_ISSET(fd, &w_fds)) {
00493                         int ret;
00494                         size_t n = len-total;
00495                         ret = write(fd,buf+total,n);
00496 
00497                         if (ret == -1 && errno == EINTR) {
00498                                 continue;
00499                         }
00500 
00501                         if (ret == -1 && 
00502                             (errno == EWOULDBLOCK || errno == EAGAIN)) {
00503                                 msleep(1);
00504                                 continue;
00505                         }
00506 
00507                         if (ret <= 0) {
00508                                 /* Don't try to write errors back
00509                                  * across the stream */
00510                                 io_multiplexing_close();
00511                                 rprintf(FERROR, RSYNC_NAME
00512                                         ": writefd_unbuffered failed to write %ld bytes: phase \"%s\": %s\n",
00513                                         (long) len, io_write_phase, 
00514                                         strerror(errno));
00515                                 exit_cleanup(RERR_STREAMIO);
00516                         }
00517 
00518                         sleep_for_bwlimit(ret);
00519  
00520                         total += ret;
00521 
00522                         if (io_timeout)
00523                                 last_io = time(NULL);
00524                 }
00525         }
00526 
00527         no_flush--;
00528 }

void io_start_buffering int    fd
 

Definition at line 534 of file io.c.

References io_buffer, io_buffer_count, multiplex_out_fd, and out_of_memory().

Referenced by do_recv(), io_start_multiplex_out(), and send_file_list().

00535 {
00536         if (io_buffer) return;
00537         multiplex_out_fd = fd;
00538         io_buffer = (char *)malloc(IO_BUFFER_SIZE);
00539         if (!io_buffer) out_of_memory("writefd");
00540         io_buffer_count = 0;
00541 }

void mplex_write int    fd,
enum logcode    code,
char *    buf,
size_t    len
[static]
 

Write an message to a multiplexed stream.

If this fails then rsync exits.

Definition at line 547 of file io.c.

References code, logcode, and writefd_unbuffered().

Referenced by io_flush(), and io_multiplex_write().

00548 {
00549         char buffer[4096];
00550         size_t n = len;
00551 
00552         SIVAL(buffer, 0, ((MPLEX_BASE + (int)code)<<24) + len);
00553 
00554         if (n > (sizeof(buffer)-4)) {
00555                 n = sizeof(buffer)-4;
00556         }
00557 
00558         memcpy(&buffer[4], buf, n);
00559         writefd_unbuffered(fd, buffer, n+4);
00560 
00561         len -= n;
00562         buf += n;
00563 
00564         if (len) {
00565                 writefd_unbuffered(fd, buf, len);
00566         }
00567 }

void io_flush void   
 

Definition at line 570 of file io.c.

References err_list_push(), FNONE, io_buffer, io_buffer_count, mplex_write(), multiplex_out_fd, no_flush, and writefd_unbuffered().

Referenced by _exit_cleanup(), client_run(), do_recv(), do_server_sender(), io_end_buffering(), io_multiplex_write(), io_start_multiplex_in(), io_start_multiplex_out(), read_timeout(), readfd(), wait_process(), and writefd().

00571 {
00572         int fd = multiplex_out_fd;
00573 
00574         err_list_push();
00575 
00576         if (!io_buffer_count || no_flush) return;
00577 
00578         if (io_multiplexing_out) {
00579                 mplex_write(fd, FNONE, io_buffer, io_buffer_count);
00580         } else {
00581                 writefd_unbuffered(fd, io_buffer, io_buffer_count);
00582         }
00583         io_buffer_count = 0;
00584 }

void io_end_buffering void   
 

Definition at line 587 of file io.c.

References io_buffer, io_flush(), and io_multiplexing_out.

Referenced by send_file_list().

00588 {
00589         io_flush();
00590         if (!io_multiplexing_out) {
00591                 free(io_buffer);
00592                 io_buffer = NULL;
00593         }
00594 }

void writefd int    fd,
char *    buf,
size_t    len
[static]
 

Definition at line 596 of file io.c.

References err_list_push(), io_buffer, io_buffer_count, io_flush(), multiplex_out_fd, stats::total_written, and writefd_unbuffered().

Referenced by write_buf(), write_int(), and write_longint().

00597 {
00598         stats.total_written += len;
00599 
00600         err_list_push();
00601 
00602         if (!io_buffer || fd != multiplex_out_fd) {
00603                 writefd_unbuffered(fd, buf, len);
00604                 return;
00605         }
00606 
00607         while (len) {
00608                 int n = MIN((int) len, IO_BUFFER_SIZE-io_buffer_count);
00609                 if (n > 0) {
00610                         memcpy(io_buffer+io_buffer_count, buf, n);
00611                         buf += n;
00612                         len -= n;
00613                         io_buffer_count += n;
00614                 }
00615                 
00616                 if (io_buffer_count == IO_BUFFER_SIZE) io_flush();
00617         }
00618 }

void write_int int    f,
int32    x
 

Definition at line 621 of file io.c.

References writefd().

Referenced by do_recv(), generate_files(), recv_files(), recv_generator(), send_deflated_token(), send_exclude_list(), send_file_entry(), send_file_list(), send_files(), send_sums(), send_uid_list(), setup_protocol(), simple_send_token(), write_int_named(), and write_longint().

00622 {
00623         char b[4];
00624         SIVAL(b,0,x);
00625         writefd(f,b,4);
00626 }

void write_int_named int    f,
int32    x,
const char *    phase
 

Definition at line 629 of file io.c.

References io_write_phase, phase_unknown, and write_int().

00630 {
00631         io_write_phase = phase;
00632         write_int(f, x);
00633         io_write_phase = phase_unknown;
00634 }

void write_longint int    f,
int64    x
 

Definition at line 641 of file io.c.

References write_int(), and writefd().

Referenced by report(), and send_file_entry().

00642 {
00643         extern int remote_version;
00644         char b[8];
00645 
00646         if (remote_version < 16 || x <= 0x7FFFFFFF) {
00647                 write_int(f, (int)x);
00648                 return;
00649         }
00650 
00651         write_int(f, (int32)0xFFFFFFFF);
00652         SIVAL(b,0,(x&0xFFFFFFFF));
00653         SIVAL(b,4,((x>>32)&0xFFFFFFFF));
00654 
00655         writefd(f,b,8);
00656 }

void write_buf int    f,
char *    buf,
size_t    len
 

Definition at line 658 of file io.c.

References writefd().

Referenced by match_sums(), send_deflated_token(), send_exclude_list(), send_file_entry(), send_files(), send_sums(), send_uid_list(), simple_send_token(), write_byte(), and write_sbuf().

00659 {
00660         writefd(f,buf,len);
00661 }

void write_sbuf int    f,
char *    buf
[static]
 

Write a string to the connection.

Definition at line 664 of file io.c.

References write_buf().

Referenced by io_printf().

00665 {
00666         write_buf(f, buf, strlen(buf));
00667 }

void write_byte int    f,
unsigned char    c
 

Definition at line 670 of file io.c.

References write_buf().

Referenced by send_deflated_token(), send_file_entry(), and send_uid_list().

00671 {
00672         write_buf(f,(char *)&c,1);
00673 }

int read_line int    f,
char *    buf,
size_t    maxlen
 

Read a line of up to maxlen characters into buf.

Does not contain a trailing newline or carriage return.

Returns:
1 for success; 0 for io error or truncation.

Definition at line 683 of file io.c.

References read_buf().

Referenced by auth_server(), rsync_module(), start_daemon(), and start_socket_client().

00684 {
00685         while (maxlen) {
00686                 buf[0] = 0;
00687                 read_buf(f, buf, 1);
00688                 if (buf[0] == 0)
00689                         return 0;
00690                 if (buf[0] == '\n') {
00691                         buf[0] = 0;
00692                         break;
00693                 }
00694                 if (buf[0] != '\r') {
00695                         buf++;
00696                         maxlen--;
00697                 }
00698         }
00699         if (maxlen == 0) {
00700                 *buf = 0;
00701                 return 0;
00702         }
00703 
00704         return 1;
00705 }

void io_printf int    fd,
const char *    format,
...   
 

Definition at line 708 of file io.c.

References vsnprintf(), and write_sbuf().

Referenced by auth_client(), auth_server(), rsync_module(), send_listing(), start_daemon(), and start_socket_client().

00709 {
00710         va_list ap;  
00711         char buf[1024];
00712         int len;
00713         
00714         va_start(ap, format);
00715         len = vsnprintf(buf, sizeof(buf), format, ap);
00716         va_end(ap);
00717 
00718         if (len < 0) exit_cleanup(RERR_STREAMIO);
00719 
00720         write_sbuf(fd, buf);
00721 }

void io_start_multiplex_out int    fd
 

Setup for multiplexing an error stream with the data stream.

Definition at line 725 of file io.c.

References io_flush(), io_multiplexing_out, io_start_buffering(), and multiplex_out_fd.

Referenced by rsync_module(), and start_server().

00726 {
00727         multiplex_out_fd = fd;
00728         io_flush();
00729         io_start_buffering(fd);
00730         io_multiplexing_out = 1;
00731 }

void io_start_multiplex_in int    fd
 

Setup for multiplexing an error stream with the data stream.

Definition at line 734 of file io.c.

References io_flush(), io_multiplexing_in, and multiplex_in_fd.

Referenced by client_run(), and start_socket_client().

00735 {
00736         multiplex_in_fd = fd;
00737         io_flush();
00738         io_multiplexing_in = 1;
00739 }

int io_multiplex_write enum logcode    code,
char *    buf,
size_t    len
 

Write an message to the multiplexed error stream.

Definition at line 742 of file io.c.

References code, io_flush(), io_multiplexing_out, logcode, mplex_write(), multiplex_out_fd, and stats::total_written.

Referenced by rwrite().

00743 {
00744         if (!io_multiplexing_out) return 0;
00745 
00746         io_flush();
00747         stats.total_written += (len+4);
00748         mplex_write(multiplex_out_fd, code, buf, len);
00749         return 1;
00750 }

void io_multiplexing_close void   
 

Stop output multiplexing.

Definition at line 753 of file io.c.

References io_multiplexing_out.

Referenced by die_from_readerr(), do_recv(), and writefd_unbuffered().

00754 {
00755         io_multiplexing_out = 0;
00756 }


Variable Documentation

int io_multiplexing_out [static]
 

Definition at line 42 of file io.c.

Referenced by io_end_buffering(), io_multiplex_write(), io_multiplexing_close(), and io_start_multiplex_out().

int io_multiplexing_in [static]
 

Definition at line 43 of file io.c.

Referenced by io_start_multiplex_in(), and read_unbuffered().

int multiplex_in_fd [static]
 

Definition at line 44 of file io.c.

Referenced by io_start_multiplex_in(), and read_unbuffered().

int multiplex_out_fd [static]
 

Definition at line 45 of file io.c.

Referenced by io_flush(), io_multiplex_write(), io_start_buffering(), io_start_multiplex_out(), and writefd().

time_t last_io [static]
 

Definition at line 46 of file io.c.

Referenced by check_timeout(), read_timeout(), and writefd_unbuffered().

int no_flush [static]
 

Definition at line 47 of file io.c.

Referenced by io_flush(), and writefd_unbuffered().

int bwlimit
 

Definition at line 49 of file io.c.

Referenced by server_options(), and sleep_for_bwlimit().

int verbose
 

Definition at line 50 of file io.c.

int io_timeout
 

Definition at line 51 of file io.c.

Referenced by check_timeout(), read_timeout(), server_options(), and writefd_unbuffered().

struct stats stats
 

Definition at line 52 of file io.c.

const char phase_unknown[] = "unknown"
 

Definition at line 55 of file io.c.

Referenced by write_int_named().

const char* io_write_phase = phase_unknown
 

The connection might be dropped at some point; perhaps because the remote instance crashed.

Just giving the offset on the stream is not very helpful. So instead we try to make io_phase_name point to something useful.

For buffered/multiplexed IO these names will be somewhat approximate; perhaps for ease of support we would rather make the buffer always flush when a single application-level IO finishes.

Todo:
Perhaps we want some simple stack functionality, but there's no need to overdo it.

Definition at line 70 of file io.c.

Referenced by write_int_named(), and writefd_unbuffered().

const char* io_read_phase = phase_unknown
 

Definition at line 71 of file io.c.

int kludge_around_eof = False
 

Ignore EOF errors while reading a module listing if the remote version is 24 or less.

Definition at line 75 of file io.c.

Referenced by start_socket_client().

int io_error_fd = -1 [static]
 

Definition at line 78 of file io.c.

Referenced by io_set_error_fd(), read_error_fd(), read_timeout(), and writefd_unbuffered().

char* io_buffer [static]
 

Definition at line 531 of file io.c.

Referenced by io_end_buffering(), io_flush(), io_start_buffering(), and writefd().

int io_buffer_count [static]
 

Definition at line 532 of file io.c.

Referenced by io_flush(), io_start_buffering(), and writefd().


Generated on Tue Apr 16 12:37:38 2002 for rsync by doxygen1.2.15