Ignore:
Timestamp:
May 27, 2009, 9:09:42 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/lib/util_sock.c

    r228 r232  
    10381038
    10391039/****************************************************************************
     1040 Write all data from an iov array
     1041****************************************************************************/
     1042
     1043ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
     1044{
     1045        int i;
     1046        size_t to_send;
     1047        ssize_t thistime;
     1048        size_t sent;
     1049        struct iovec *iov_copy, *iov;
     1050
     1051        to_send = 0;
     1052        for (i=0; i<iovcnt; i++) {
     1053                to_send += orig_iov[i].iov_len;
     1054        }
     1055
     1056        thistime = sys_writev(fd, orig_iov, iovcnt);
     1057        if ((thistime <= 0) || (thistime == to_send)) {
     1058                return thistime;
     1059        }
     1060        sent = thistime;
     1061
     1062        /*
     1063         * We could not send everything in one call. Make a copy of iov that
     1064         * we can mess with. We keep a copy of the array start in iov_copy for
     1065         * the TALLOC_FREE, because we're going to modify iov later on,
     1066         * discarding elements.
     1067         */
     1068
     1069        iov_copy = (struct iovec *)TALLOC_MEMDUP(
     1070                talloc_tos(), orig_iov, sizeof(struct iovec) * iovcnt);
     1071
     1072        if (iov_copy == NULL) {
     1073                errno = ENOMEM;
     1074                return -1;
     1075        }
     1076        iov = iov_copy;
     1077
     1078        while (sent < to_send) {
     1079                /*
     1080                 * We have to discard "thistime" bytes from the beginning
     1081                 * iov array, "thistime" contains the number of bytes sent
     1082                 * via writev last.
     1083                 */
     1084                while (thistime > 0) {
     1085                        if (thistime < iov[0].iov_len) {
     1086                                char *new_base =
     1087                                        (char *)iov[0].iov_base + thistime;
     1088                                iov[0].iov_base = new_base;
     1089                                iov[0].iov_len -= thistime;
     1090                                break;
     1091                        }
     1092                        thistime -= iov[0].iov_len;
     1093                        iov += 1;
     1094                        iovcnt -= 1;
     1095                }
     1096
     1097                thistime = sys_writev(fd, iov, iovcnt);
     1098                if (thistime <= 0) {
     1099                        break;
     1100                }
     1101                sent += thistime;
     1102        }
     1103
     1104        TALLOC_FREE(iov_copy);
     1105        return sent;
     1106}
     1107
     1108/****************************************************************************
    10401109 Write data to a fd.
    10411110****************************************************************************/
    10421111
     1112/****************************************************************************
     1113 Write data to a fd.
     1114****************************************************************************/
     1115
    10431116ssize_t write_data(int fd, const char *buffer, size_t N)
    10441117{
    1045         size_t total=0;
    10461118        ssize_t ret;
    1047         char addr[INET6_ADDRSTRLEN];
    1048 
    1049         while (total < N) {
    1050                 ret = sys_write(fd,buffer + total,N - total);
    1051 
    1052                 if (ret == -1) {
    1053                         if (fd == get_client_fd()) {
    1054                                 /* Try and give an error message saying
    1055                                  * what client failed. */
    1056                                 DEBUG(0,("write_data: write failure in "
    1057                                         "writing to client %s. Error %s\n",
    1058                                         get_peer_addr(fd,addr,sizeof(addr)),
    1059                                         strerror(errno) ));
    1060                         } else {
    1061                                 DEBUG(0,("write_data: write failure. "
    1062                                         "Error = %s\n", strerror(errno) ));
    1063                         }
    1064                         return -1;
    1065                 }
    1066 
    1067                 if (ret == 0) {
    1068                         return total;
    1069                 }
    1070 
    1071                 total += ret;
    1072         }
    1073         return (ssize_t)total;
     1119        struct iovec iov;
     1120
     1121        iov.iov_base = CONST_DISCARD(char *, buffer);
     1122        iov.iov_len = N;
     1123
     1124        ret = write_data_iov(fd, &iov, 1);
     1125        if (ret >= 0) {
     1126                return ret;
     1127        }
     1128
     1129        if (fd == get_client_fd()) {
     1130                char addr[INET6_ADDRSTRLEN];
     1131                /*
     1132                 * Try and give an error message saying what client failed.
     1133                 */
     1134                DEBUG(0, ("write_data: write failure in writing to client %s. "
     1135                          "Error %s\n", get_peer_addr(fd,addr,sizeof(addr)),
     1136                          strerror(errno)));
     1137        } else {
     1138                DEBUG(0,("write_data: write failure. Error = %s\n",
     1139                         strerror(errno) ));
     1140        }
     1141
     1142        return -1;
    10741143}
    10751144
     
    20172086{
    20182087        TALLOC_CTX *ctx = talloc_tos();
     2088        char addr[INET6_ADDRSTRLEN];
    20192089        char *name = NULL;
    20202090        const char *dnsname;
     
    20682138                /* Use DNS to resolve the name, but only the first address */
    20692139                struct sockaddr_storage ss;
    2070                 if (interpret_string_addr(&ss, servername,0)) {
    2071                         print_sockaddr(name,
    2072                                         sizeof(name),
     2140                if (interpret_string_addr(&ss, servername, 0)) {
     2141                        print_sockaddr(addr,
     2142                                        sizeof(addr),
    20732143                                        &ss);
    2074                         servername = name;
     2144                        servername = addr;
    20752145                }
    20762146        }
Note: See TracChangeset for help on using the changeset viewer.