~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to mutt_socket.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-06-07 17:30:03 UTC
  • mto: (16.2.1 experimental) (2.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090607173003-rg37ui3h2bbv7wl0
Tags: upstream-1.5.19
ImportĀ upstreamĀ versionĀ 1.5.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 1998 Michael R. Elkins <me@mutt.org>
3
 
 * Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>
 
2
 * Copyright (C) 1998,2000 Michael R. Elkins <me@mutt.org>
 
3
 * Copyright (C) 1999-2006,2008 Brendan Cully <brendan@kublai.com>
4
4
 * Copyright (C) 1999-2000 Tommi Komulainen <Tommi.Komulainen@iki.fi>
5
5
 * 
6
6
 *     This program is free software; you can redistribute it and/or modify
112
112
int mutt_socket_write_d (CONNECTION *conn, const char *buf, int len, int dbg)
113
113
{
114
114
  int rc;
 
115
  int sent = 0;
115
116
 
116
117
  dprint (dbg, (debugfile,"%d> %s", conn->fd, buf));
117
118
 
123
124
 
124
125
  if (len < 0)
125
126
    len = mutt_strlen (buf);
126
 
  if ((rc = conn->conn_write (conn, buf, len)) < 0)
127
 
  {
128
 
    dprint (1, (debugfile,
129
 
      "mutt_socket_write: error writing, closing socket\n"));
130
 
    mutt_socket_close (conn);
131
 
 
132
 
    return -1;
133
 
  }
134
 
 
135
 
  if (rc < len)
136
 
  {
137
 
    dprint (1, (debugfile,
138
 
      "mutt_socket_write: ERROR: wrote %d of %d bytes!\n", rc, len));
139
 
  }
140
 
 
141
 
  return rc;
 
127
  
 
128
  while (sent < len)
 
129
  {
 
130
    if ((rc = conn->conn_write (conn, buf + sent, len - sent)) < 0)
 
131
    {
 
132
      dprint (1, (debugfile,
 
133
                  "mutt_socket_write: error writing (%s), closing socket\n",
 
134
                  strerror(errno)));
 
135
      mutt_socket_close (conn);
 
136
 
 
137
      return -1;
 
138
    }
 
139
 
 
140
    if (rc < len - sent)
 
141
      dprint (3, (debugfile,
 
142
                  "mutt_socket_write: short write (%d of %d bytes)\n", rc,
 
143
                  len - sent));
 
144
    
 
145
    sent += rc;
 
146
  }
 
147
 
 
148
  return sent;
142
149
}
143
150
 
144
151
/* poll whether reads would block.
205
212
 
206
213
  /* strip \r from \r\n termination */
207
214
  if (i && buf[i-1] == '\r')
208
 
    buf[--i] = '\0';
209
 
  else
210
 
    buf[i] = '\0';
 
215
    i--;
 
216
  buf[i] = '\0';
211
217
 
212
218
  dprint (dbg, (debugfile, "%d< %s\n", conn->fd, buf));
213
219
  
468
474
  host_idna = conn->account.host;
469
475
# endif
470
476
 
471
 
  mutt_message (_("Looking up %s..."), conn->account.host);
472
 
 
 
477
  if (!option(OPTNOCURSES))
 
478
    mutt_message (_("Looking up %s..."), conn->account.host);
473
479
  
474
480
  rc = getaddrinfo (host_idna, port, &hints, &res);
475
481
 
484
490
    return -1;
485
491
  }
486
492
 
487
 
  mutt_message (_("Connecting to %s..."), conn->account.host); 
 
493
  if (!option(OPTNOCURSES))
 
494
    mutt_message (_("Connecting to %s..."), conn->account.host); 
488
495
 
489
496
  rc = -1;
490
497
  for (cur = res; cur != NULL; cur = cur->ai_next)
526
533
  host_idna = conn->account.host;
527
534
# endif
528
535
 
529
 
  mutt_message (_("Looking up %s..."), conn->account.host);
530
 
 
531
 
  if ((he = gethostbyname (host_idna)) == NULL)
532
 
  {
 
536
  if (!option(OPTNOCURSES))
 
537
    mutt_message (_("Looking up %s..."), conn->account.host);
 
538
 
 
539
  he = gethostbyname (host_idna);
 
540
 
533
541
# ifdef HAVE_LIBIDN
534
542
    FREE (&host_idna);
535
543
# endif
 
544
 
 
545
  if (! he) {
536
546
    mutt_error (_("Could not find the host \"%s\""), conn->account.host);
537
547
        
538
548
    return -1;
539
549
  }
540
550
 
541
 
# ifdef HAVE_LIBIDN
542
 
  FREE (&host_idna);
543
 
# endif
544
 
 
545
 
  mutt_message (_("Connecting to %s..."), conn->account.host); 
 
551
  if (!option(OPTNOCURSES))
 
552
    mutt_message (_("Connecting to %s..."), conn->account.host); 
546
553
 
547
554
  rc = -1;
548
555
  for (i = 0; he->h_addr_list[i] != NULL; i++)