Changeset 101793 in vbox
- Timestamp:
- Nov 4, 2023 9:26:00 PM (13 months ago)
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/Makefile.kmk
r101790 r101793 189 189 nsprpub/pr/include/prmem.h \ 190 190 nsprpub/pr/include/prmon.h \ 191 nsprpub/pr/include/prnetdb.h \192 191 nsprpub/pr/include/prpdce.h \ 193 192 nsprpub/pr/include/prprf.h \ … … 515 514 nsprpub/pr/src/io/prfdcach.c \ 516 515 nsprpub/pr/src/io/priometh.c \ 517 nsprpub/pr/src/io/pripv6.c \518 516 nsprpub/pr/src/io/prmapopt.c \ 519 517 nsprpub/pr/src/io/prlayer.c \ … … 540 538 nsprpub/pr/src/misc/prlog2.c \ 541 539 nsprpub/pr/src/misc/prlong.c \ 542 nsprpub/pr/src/misc/prnetdb.c \543 540 nsprpub/pr/src/misc/prtime.c \ 544 541 nsprpub/pr/src/threads/prcmon.c \ -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/prio.h
r11551 r101793 103 103 #define PR_MakeDir VBoxNsprPR_MakeDir 104 104 #define PR_RmDir VBoxNsprPR_RmDir 105 #define PR_NewUDPSocket VBoxNsprPR_NewUDPSocket106 #define PR_NewTCPSocket VBoxNsprPR_NewTCPSocket107 #define PR_OpenUDPSocket VBoxNsprPR_OpenUDPSocket108 105 #define PR_OpenTCPSocket VBoxNsprPR_OpenTCPSocket 109 106 #define PR_ConnectContinue VBoxNsprPR_ConnectContinue … … 116 113 #define PR_TransmitFile VBoxNsprPR_TransmitFile 117 114 #define PR_SendFile VBoxNsprPR_SendFile 118 #define PR_NewTCPSocketPair VBoxNsprPR_NewTCPSocketPair119 115 #define PR_GetSockName VBoxNsprPR_GetSockName 120 116 #define PR_GetPeerName VBoxNsprPR_GetPeerName … … 1255 1251 /* 1256 1252 ************************************************************************* 1257 * FUNCTION: PR_NewUDPSocket1258 * DESCRIPTION:1259 * Create a new UDP socket.1260 * INPUTS:1261 * None1262 * OUTPUTS:1263 * None1264 * RETURN: PRFileDesc*1265 * Upon successful completion, PR_NewUDPSocket returns a pointer1266 * to the PRFileDesc created for the newly opened UDP socket.1267 * Returns a NULL pointer if the creation of a new UDP socket failed.1268 *1269 **************************************************************************1270 */1271 1272 NSPR_API(PRFileDesc*) PR_NewUDPSocket(void);1273 1274 /*1275 *************************************************************************1276 * FUNCTION: PR_NewTCPSocket1277 * DESCRIPTION:1278 * Create a new TCP socket.1279 * INPUTS:1280 * None1281 * OUTPUTS:1282 * None1283 * RETURN: PRFileDesc*1284 * Upon successful completion, PR_NewTCPSocket returns a pointer1285 * to the PRFileDesc created for the newly opened TCP socket.1286 * Returns a NULL pointer if the creation of a new TCP socket failed.1287 *1288 **************************************************************************1289 */1290 1291 NSPR_API(PRFileDesc*) PR_NewTCPSocket(void);1292 1293 /*1294 *************************************************************************1295 * FUNCTION: PR_OpenUDPSocket1296 * DESCRIPTION:1297 * Create a new UDP socket of the specified address family.1298 * INPUTS:1299 * PRIntn af1300 * Address family1301 * OUTPUTS:1302 * None1303 * RETURN: PRFileDesc*1304 * Upon successful completion, PR_OpenUDPSocket returns a pointer1305 * to the PRFileDesc created for the newly opened UDP socket.1306 * Returns a NULL pointer if the creation of a new UDP socket failed.1307 *1308 **************************************************************************1309 */1310 1311 NSPR_API(PRFileDesc*) PR_OpenUDPSocket(PRIntn af);1312 1313 /*1314 *************************************************************************1315 1253 * FUNCTION: PR_OpenTCPSocket 1316 1254 * DESCRIPTION: … … 1801 1739 /* 1802 1740 ************************************************************************* 1803 ** FUNCTION: PR_NewTCPSocketPair1804 ** DESCRIPTION:1805 ** Create a new TCP socket pair. The returned descriptors can be used1806 ** interchangeably; they are interconnected full-duplex descriptors: data1807 ** written to one can be read from the other and vice-versa.1808 **1809 ** INPUTS:1810 ** None1811 ** OUTPUTS:1812 ** PRFileDesc *fds[2]1813 ** The file descriptor pair for the newly created TCP sockets.1814 ** RETURN: PRStatus1815 ** Upon successful completion of TCP socket pair, PR_NewTCPSocketPair1816 ** returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further1817 ** failure information can be obtained by calling PR_GetError().1818 ** XXX can we implement this on windoze and mac?1819 **************************************************************************1820 **/1821 NSPR_API(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2]);1822 1823 /*1824 *************************************************************************1825 1741 ** FUNCTION: PR_GetSockName 1826 1742 ** DESCRIPTION: -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
r101778 r101793 216 216 _PR_InitCMon(); 217 217 _PR_InitIO(); 218 _PR_InitNet();219 218 _PR_InitLog(); 220 219 _PR_InitLinker(); … … 223 222 224 223 nspr_InitializePRErrorTable(); 225 226 #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)227 _pr_init_ipv6();228 #endif229 224 230 225 _PR_MD_FINAL_INIT(); … … 429 424 * _PR_XXXCleanup() that we can call here. 430 425 */ 431 _PR_CleanupNet();432 426 _PR_CleanupIO(); 433 427 #ifdef WINNT -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptio.c
r50011 r101793 336 336 PRSize amount; /* #3 - size of 'buffer', or */ 337 337 pt_SockLen *addr_len; /* - length of address */ 338 #ifdef HPUX11339 /*340 * For sendfile()341 */342 struct file_spec {343 off_t offset; /* offset in file to send */344 size_t nbytes; /* length of file data to send */345 size_t st_size; /* file size */346 } file_spec;347 #endif348 338 } arg3; 349 339 union { PRIntn flags; } arg4; /* #4 - read/write flags */ 350 340 union { PRNetAddr *addr; } arg5; /* #5 - send/recv address */ 351 352 #ifdef HPUX11353 /*354 * For sendfile()355 */356 int filedesc; /* descriptor of file to send */357 int nbytes_to_send; /* size of header and file */358 #endif /* HPUX11 */359 341 360 342 #ifdef SOLARIS … … 970 952 } /* pt_recvfrom_cont */ 971 953 972 #ifdef AIX973 static PRBool pt_aix_sendfile_cont(pt_Continuation *op, PRInt16 revents)974 {975 struct sf_parms *sf_struct = (struct sf_parms *) op->arg2.buffer;976 ssize_t rv;977 unsigned long long saved_file_offset;978 long long saved_file_bytes;979 980 saved_file_offset = sf_struct->file_offset;981 saved_file_bytes = sf_struct->file_bytes;982 sf_struct->bytes_sent = 0;983 984 if ((sf_struct->file_bytes > 0) && (sf_struct->file_size > 0))985 PR_ASSERT((sf_struct->file_bytes + sf_struct->file_offset) <=986 sf_struct->file_size);987 rv = AIX_SEND_FILE(&op->arg1.osfd, sf_struct, op->arg4.flags);988 op->syserrno = errno;989 990 if (rv != -1) {991 op->result.code += sf_struct->bytes_sent;992 /*993 * A bug in AIX 4.3.2 prevents the 'file_bytes' field from994 * being updated. So, 'file_bytes' is maintained by NSPR to995 * avoid conflict when this bug is fixed in AIX, in the future.996 */997 if (saved_file_bytes != -1)998 saved_file_bytes -= (sf_struct->file_offset - saved_file_offset);999 sf_struct->file_bytes = saved_file_bytes;1000 } else if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN) {1001 op->result.code = -1;1002 } else {1003 return PR_FALSE;1004 }1005 1006 if (rv == 1) { /* more data to send */1007 return PR_FALSE;1008 }1009 1010 return PR_TRUE;1011 }1012 #endif /* AIX */1013 1014 #ifdef HPUX111015 static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)1016 {1017 struct iovec *hdtrl = (struct iovec *) op->arg2.buffer;1018 int count;1019 1020 count = sendfile(op->arg1.osfd, op->filedesc, op->arg3.file_spec.offset,1021 op->arg3.file_spec.nbytes, hdtrl, op->arg4.flags);1022 PR_ASSERT(count <= op->nbytes_to_send);1023 op->syserrno = errno;1024 1025 if (count != -1) {1026 op->result.code += count;1027 } else if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN) {1028 op->result.code = -1;1029 } else {1030 return PR_FALSE;1031 }1032 if (count != -1 && count < op->nbytes_to_send) {1033 if (count < hdtrl[0].iov_len) {1034 /* header not sent */1035 1036 hdtrl[0].iov_base = ((char *) hdtrl[0].iov_len) + count;1037 hdtrl[0].iov_len -= count;1038 1039 } else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes)) {1040 /* header sent, file not sent */1041 PRUint32 file_nbytes_sent = count - hdtrl[0].iov_len;1042 1043 hdtrl[0].iov_base = NULL;1044 hdtrl[0].iov_len = 0;1045 1046 op->arg3.file_spec.offset += file_nbytes_sent;1047 op->arg3.file_spec.nbytes -= file_nbytes_sent;1048 } else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes +1049 hdtrl[1].iov_len)) {1050 PRUint32 trailer_nbytes_sent = count - (hdtrl[0].iov_len +1051 op->arg3.file_spec.nbytes);1052 1053 /* header sent, file sent, trailer not sent */1054 1055 hdtrl[0].iov_base = NULL;1056 hdtrl[0].iov_len = 0;1057 /*1058 * set file offset and len so that no more file data is1059 * sent1060 */1061 op->arg3.file_spec.offset = op->arg3.file_spec.st_size;1062 op->arg3.file_spec.nbytes = 0;1063 1064 hdtrl[1].iov_base =((char *) hdtrl[1].iov_base)+ trailer_nbytes_sent;1065 hdtrl[1].iov_len -= trailer_nbytes_sent;1066 }1067 op->nbytes_to_send -= count;1068 return PR_FALSE;1069 }1070 1071 return PR_TRUE;1072 }1073 #endif /* HPUX11 */1074 1075 954 #ifdef SOLARIS 1076 955 static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents) … … 1567 1446 pt_SockLen addr_len; 1568 1447 const PRNetAddr *addrp = addr; 1569 #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)1448 #if defined(_PR_HAVE_SOCKADDR_LEN) 1570 1449 PRUint16 md_af = addr->raw.family; 1571 1450 PRNetAddr addrCopy; … … 1576 1455 PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); 1577 1456 addr_len = PR_NETADDR_SIZE(addr); 1578 #if defined(_PR_INET6)1579 if (addr->raw.family == PR_AF_INET6) {1580 md_af = AF_INET6;1581 #ifndef _PR_HAVE_SOCKADDR_LEN1582 addrCopy = *addr;1583 addrCopy.raw.family = AF_INET6;1584 addrp = &addrCopy;1585 #endif1586 }1587 #endif1588 1457 1589 1458 #ifdef _PR_HAVE_SOCKADDR_LEN … … 1721 1590 } 1722 1591 #endif /* _PR_HAVE_SOCKADDR_LEN */ 1723 #ifdef _PR_INET61724 if (addr && (AF_INET6 == addr->raw.family))1725 addr->raw.family = PR_AF_INET6;1726 #endif1727 1592 newfd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_TRUE, PR_FALSE); 1728 1593 if (newfd == NULL) close(osfd); /* $$$ whoops! this doesn't work $$$ */ … … 1752 1617 pt_SockLen addr_len; 1753 1618 const PRNetAddr *addrp = addr; 1754 #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)1619 #if defined(_PR_HAVE_SOCKADDR_LEN) 1755 1620 PRUint16 md_af = addr->raw.family; 1756 1621 PRNetAddr addrCopy; … … 1769 1634 } 1770 1635 } 1771 1772 #if defined(_PR_INET6)1773 if (addr->raw.family == PR_AF_INET6) {1774 md_af = AF_INET6;1775 #ifndef _PR_HAVE_SOCKADDR_LEN1776 addrCopy = *addr;1777 addrCopy.raw.family = AF_INET6;1778 addrp = &addrCopy;1779 #endif1780 }1781 #endif1782 1636 1783 1637 addr_len = PR_NETADDR_SIZE(addr); … … 1992 1846 return pt_Send(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT); 1993 1847 } /* pt_SocketWrite */ 1994 1995 static PRInt32 pt_SendTo(1996 PRFileDesc *fd, const void *buf,1997 PRInt32 amount, PRIntn flags, const PRNetAddr *addr,1998 PRIntervalTime timeout)1999 {2000 PRInt32 syserrno, bytes = -1;2001 PRBool fNeedContinue = PR_FALSE;2002 pt_SockLen addr_len;2003 const PRNetAddr *addrp = addr;2004 #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)2005 PRUint16 md_af = addr->raw.family;2006 PRNetAddr addrCopy;2007 #endif2008 2009 if (pt_TestAbort()) return bytes;2010 2011 PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);2012 #if defined(_PR_INET6)2013 if (addr->raw.family == PR_AF_INET6) {2014 md_af = AF_INET6;2015 #ifndef _PR_HAVE_SOCKADDR_LEN2016 addrCopy = *addr;2017 addrCopy.raw.family = AF_INET6;2018 addrp = &addrCopy;2019 #endif2020 }2021 #endif2022 2023 addr_len = PR_NETADDR_SIZE(addr);2024 #ifdef _PR_HAVE_SOCKADDR_LEN2025 addrCopy = *addr;2026 ((struct sockaddr*)&addrCopy)->sa_len = addr_len;2027 ((struct sockaddr*)&addrCopy)->sa_family = md_af;2028 bytes = sendto(2029 fd->secret->md.osfd, buf, amount, flags,2030 (struct sockaddr*)&addrCopy, addr_len);2031 #else2032 bytes = sendto(2033 fd->secret->md.osfd, buf, amount, flags,2034 (struct sockaddr*)addrp, addr_len);2035 #endif2036 syserrno = errno;2037 if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)2038 && (!fd->secret->nonblocking) )2039 {2040 if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;2041 else fNeedContinue = PR_TRUE;2042 }2043 if (fNeedContinue == PR_TRUE)2044 {2045 pt_Continuation op;2046 op.arg1.osfd = fd->secret->md.osfd;2047 op.arg2.buffer = (void*)buf;2048 op.arg3.amount = amount;2049 op.arg4.flags = flags;2050 #ifdef _PR_HAVE_SOCKADDR_LEN2051 op.arg5.addr = (PRNetAddr*)&addrCopy;2052 #else2053 op.arg5.addr = (PRNetAddr*)addr;2054 #endif2055 op.timeout = timeout;2056 op.result.code = 0; /* initialize the number sent */2057 op.function = pt_sendto_cont;2058 op.event = POLLOUT | POLLPRI;2059 bytes = pt_Continue(&op);2060 syserrno = op.syserrno;2061 }2062 if (bytes < 0)2063 pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno);2064 return bytes;2065 } /* pt_SendTo */2066 2067 static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,2068 PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)2069 {2070 PRBool fNeedContinue = PR_FALSE;2071 PRInt32 syserrno, bytes = -1;2072 pt_SockLen addr_len = sizeof(PRNetAddr);2073 2074 if (pt_TestAbort()) return bytes;2075 2076 bytes = recvfrom(2077 fd->secret->md.osfd, buf, amount, flags,2078 (struct sockaddr*)addr, &addr_len);2079 syserrno = errno;2080 2081 if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)2082 && (!fd->secret->nonblocking) )2083 {2084 if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;2085 else fNeedContinue = PR_TRUE;2086 }2087 2088 if (fNeedContinue == PR_TRUE)2089 {2090 pt_Continuation op;2091 op.arg1.osfd = fd->secret->md.osfd;2092 op.arg2.buffer = buf;2093 op.arg3.amount = amount;2094 op.arg4.flags = flags;2095 op.arg5.addr = addr;2096 op.timeout = timeout;2097 op.function = pt_recvfrom_cont;2098 op.event = POLLIN | POLLPRI;2099 bytes = pt_Continue(&op);2100 syserrno = op.syserrno;2101 }2102 #ifdef _PR_HAVE_SOCKADDR_LEN2103 if (bytes >= 0)2104 {2105 /* ignore the sa_len field of struct sockaddr */2106 if (addr)2107 {2108 addr->raw.family = ((struct sockaddr*)addr)->sa_family;2109 }2110 }2111 #endif /* _PR_HAVE_SOCKADDR_LEN */2112 #ifdef _PR_INET62113 if (addr && (AF_INET6 == addr->raw.family))2114 addr->raw.family = PR_AF_INET6;2115 #endif2116 if (bytes < 0)2117 pt_MapError(_PR_MD_MAP_RECVFROM_ERROR, syserrno);2118 return bytes;2119 } /* pt_RecvFrom */2120 2121 #ifdef AIX2122 #ifndef HAVE_SEND_FILE2123 static pthread_once_t pt_aix_sendfile_once_block = PTHREAD_ONCE_INIT;2124 2125 static void pt_aix_sendfile_init_routine(void)2126 {2127 void *handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);2128 pt_aix_sendfile_fptr = (ssize_t (*)()) dlsym(handle, "send_file");2129 dlclose(handle);2130 }2131 2132 /*2133 * pt_AIXDispatchSendFile2134 */2135 static PRInt32 pt_AIXDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,2136 PRTransmitFileFlags flags, PRIntervalTime timeout)2137 {2138 int rv;2139 2140 rv = pthread_once(&pt_aix_sendfile_once_block,2141 pt_aix_sendfile_init_routine);2142 PR_ASSERT(0 == rv);2143 if (pt_aix_sendfile_fptr) {2144 return pt_AIXSendFile(sd, sfd, flags, timeout);2145 } else {2146 return PR_EmulateSendFile(sd, sfd, flags, timeout);2147 }2148 }2149 #endif /* !HAVE_SEND_FILE */2150 2151 2152 /*2153 * pt_AIXSendFile2154 *2155 * Send file sfd->fd across socket sd. If specified, header and trailer2156 * buffers are sent before and after the file, respectively.2157 *2158 * PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file2159 *2160 * return number of bytes sent or -1 on error2161 *2162 * This implementation takes advantage of the send_file() system2163 * call available in AIX 4.3.2.2164 */2165 2166 static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,2167 PRTransmitFileFlags flags, PRIntervalTime timeout)2168 {2169 struct sf_parms sf_struct;2170 uint_t send_flags;2171 ssize_t rv;2172 int syserrno;2173 PRInt32 count;2174 unsigned long long saved_file_offset;2175 long long saved_file_bytes;2176 2177 sf_struct.header_data = (void *) sfd->header; /* cast away the 'const' */2178 sf_struct.header_length = sfd->hlen;2179 sf_struct.file_descriptor = sfd->fd->secret->md.osfd;2180 sf_struct.file_size = 0;2181 sf_struct.file_offset = sfd->file_offset;2182 if (sfd->file_nbytes == 0)2183 sf_struct.file_bytes = -1;2184 else2185 sf_struct.file_bytes = sfd->file_nbytes;2186 sf_struct.trailer_data = (void *) sfd->trailer;2187 sf_struct.trailer_length = sfd->tlen;2188 sf_struct.bytes_sent = 0;2189 2190 saved_file_offset = sf_struct.file_offset;2191 saved_file_bytes = sf_struct.file_bytes;2192 2193 send_flags = 0; /* flags processed at the end */2194 2195 /* The first argument to send_file() is int*. */2196 PR_ASSERT(sizeof(int) == sizeof(sd->secret->md.osfd));2197 do {2198 rv = AIX_SEND_FILE(&sd->secret->md.osfd, &sf_struct, send_flags);2199 } while (rv == -1 && (syserrno = errno) == EINTR);2200 2201 if (rv == -1) {2202 if (syserrno == EAGAIN || syserrno == EWOULDBLOCK) {2203 count = 0; /* Not a real error. Need to continue. */2204 } else {2205 count = -1;2206 }2207 } else {2208 count = sf_struct.bytes_sent;2209 /*2210 * A bug in AIX 4.3.2 prevents the 'file_bytes' field from2211 * being updated. So, 'file_bytes' is maintained by NSPR to2212 * avoid conflict when this bug is fixed in AIX, in the future.2213 */2214 if (saved_file_bytes != -1)2215 saved_file_bytes -= (sf_struct.file_offset - saved_file_offset);2216 sf_struct.file_bytes = saved_file_bytes;2217 }2218 2219 if ((rv == 1) || ((rv == -1) && (count == 0))) {2220 pt_Continuation op;2221 2222 op.arg1.osfd = sd->secret->md.osfd;2223 op.arg2.buffer = &sf_struct;2224 op.arg4.flags = send_flags;2225 op.result.code = count;2226 op.timeout = timeout;2227 op.function = pt_aix_sendfile_cont;2228 op.event = POLLOUT | POLLPRI;2229 count = pt_Continue(&op);2230 syserrno = op.syserrno;2231 }2232 2233 if (count == -1) {2234 pt_MapError(_MD_aix_map_sendfile_error, syserrno);2235 return -1;2236 }2237 if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {2238 PR_Close(sd);2239 }2240 PR_ASSERT(count == (sfd->hlen + sfd->tlen +2241 ((sfd->file_nbytes == 0) ?2242 sf_struct.file_size - sfd->file_offset :2243 sfd->file_nbytes)));2244 return count;2245 }2246 #endif /* AIX */2247 2248 #ifdef HPUX112249 /*2250 * pt_HPUXSendFile2251 *2252 * Send file sfd->fd across socket sd. If specified, header and trailer2253 * buffers are sent before and after the file, respectively.2254 *2255 * PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file2256 *2257 * return number of bytes sent or -1 on error2258 *2259 * This implementation takes advantage of the sendfile() system2260 * call available in HP-UX B.11.00.2261 */2262 2263 static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,2264 PRTransmitFileFlags flags, PRIntervalTime timeout)2265 {2266 struct stat statbuf;2267 size_t nbytes_to_send, file_nbytes_to_send;2268 struct iovec hdtrl[2]; /* optional header and trailer buffers */2269 int send_flags;2270 PRInt32 count;2271 int syserrno;2272 2273 if (sfd->file_nbytes == 0) {2274 /* Get file size */2275 if (fstat(sfd->fd->secret->md.osfd, &statbuf) == -1) {2276 _PR_MD_MAP_FSTAT_ERROR(errno);2277 return -1;2278 }2279 file_nbytes_to_send = statbuf.st_size - sfd->file_offset;2280 } else {2281 file_nbytes_to_send = sfd->file_nbytes;2282 }2283 nbytes_to_send = sfd->hlen + sfd->tlen + file_nbytes_to_send;2284 2285 hdtrl[0].iov_base = (void *) sfd->header; /* cast away the 'const' */2286 hdtrl[0].iov_len = sfd->hlen;2287 hdtrl[1].iov_base = (void *) sfd->trailer;2288 hdtrl[1].iov_len = sfd->tlen;2289 /*2290 * SF_DISCONNECT seems to close the socket even if sendfile()2291 * only does a partial send on a nonblocking socket. This2292 * would prevent the subsequent sendfile() calls on that socket2293 * from working. So we don't use the SD_DISCONNECT flag.2294 */2295 send_flags = 0;2296 2297 do {2298 count = sendfile(sd->secret->md.osfd, sfd->fd->secret->md.osfd,2299 sfd->file_offset, file_nbytes_to_send, hdtrl, send_flags);2300 } while (count == -1 && (syserrno = errno) == EINTR);2301 2302 if (count == -1 && (syserrno == EAGAIN || syserrno == EWOULDBLOCK)) {2303 count = 0;2304 }2305 if (count != -1 && count < nbytes_to_send) {2306 pt_Continuation op;2307 2308 if (count < sfd->hlen) {2309 /* header not sent */2310 2311 hdtrl[0].iov_base = ((char *) sfd->header) + count;2312 hdtrl[0].iov_len = sfd->hlen - count;2313 op.arg3.file_spec.offset = sfd->file_offset;2314 op.arg3.file_spec.nbytes = file_nbytes_to_send;2315 } else if (count < (sfd->hlen + file_nbytes_to_send)) {2316 /* header sent, file not sent */2317 2318 hdtrl[0].iov_base = NULL;2319 hdtrl[0].iov_len = 0;2320 2321 op.arg3.file_spec.offset = sfd->file_offset + count - sfd->hlen;2322 op.arg3.file_spec.nbytes = file_nbytes_to_send - (count - sfd->hlen);2323 } else if (count < (sfd->hlen + file_nbytes_to_send + sfd->tlen)) {2324 PRUint32 trailer_nbytes_sent;2325 2326 /* header sent, file sent, trailer not sent */2327 2328 hdtrl[0].iov_base = NULL;2329 hdtrl[0].iov_len = 0;2330 /*2331 * set file offset and len so that no more file data is2332 * sent2333 */2334 op.arg3.file_spec.offset = statbuf.st_size;2335 op.arg3.file_spec.nbytes = 0;2336 2337 trailer_nbytes_sent = count - sfd->hlen - file_nbytes_to_send;2338 hdtrl[1].iov_base = ((char *) sfd->trailer) + trailer_nbytes_sent;2339 hdtrl[1].iov_len = sfd->tlen - trailer_nbytes_sent;2340 }2341 2342 op.arg1.osfd = sd->secret->md.osfd;2343 op.filedesc = sfd->fd->secret->md.osfd;2344 op.arg2.buffer = hdtrl;2345 op.arg3.file_spec.st_size = statbuf.st_size;2346 op.arg4.flags = send_flags;2347 op.nbytes_to_send = nbytes_to_send - count;2348 op.result.code = count;2349 op.timeout = timeout;2350 op.function = pt_hpux_sendfile_cont;2351 op.event = POLLOUT | POLLPRI;2352 count = pt_Continue(&op);2353 syserrno = op.syserrno;2354 }2355 2356 if (count == -1) {2357 pt_MapError(_MD_hpux_map_sendfile_error, syserrno);2358 return -1;2359 }2360 if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {2361 PR_Close(sd);2362 }2363 PR_ASSERT(count == nbytes_to_send);2364 return count;2365 }2366 2367 #endif /* HPUX11 */2368 1848 2369 1849 #ifdef SOLARIS … … 2686 2166 #endif /* LINUX */ 2687 2167 2688 #ifdef AIX2689 extern int _pr_aix_send_file_use_disabled;2690 #endif2691 2692 2168 static PRInt32 pt_SendFile( 2693 2169 PRFileDesc *sd, PRSendFileData *sfd, … … 2701 2177 return -1; 2702 2178 } 2703 #ifdef HPUX11 2704 return(pt_HPUXSendFile(sd, sfd, flags, timeout)); 2705 #elif defined(AIX) 2706 #ifdef HAVE_SEND_FILE 2707 /* 2708 * A bug in AIX 4.3.2 results in corruption of data transferred by 2709 * send_file(); AIX patch PTF U463956 contains the fix. A user can 2710 * disable the use of send_file function in NSPR, when this patch is 2711 * not installed on the system, by setting the envionment variable 2712 * NSPR_AIX_SEND_FILE_USE_DISABLED to 1. 2713 */ 2714 if (_pr_aix_send_file_use_disabled) 2715 return(PR_EmulateSendFile(sd, sfd, flags, timeout)); 2716 else 2717 return(pt_AIXSendFile(sd, sfd, flags, timeout)); 2718 #else 2719 return(PR_EmulateSendFile(sd, sfd, flags, timeout)); 2720 /* return(pt_AIXDispatchSendFile(sd, sfd, flags, timeout));*/ 2721 #endif /* HAVE_SEND_FILE */ 2722 #elif defined(SOLARIS) 2179 #if defined(SOLARIS) 2723 2180 #ifdef HAVE_SENDFILEV 2724 2181 return(pt_SolarisSendFile(sd, sfd, flags, timeout)); … … 2788 2245 } 2789 2246 #endif /* _PR_HAVE_SOCKADDR_LEN */ 2790 #ifdef _PR_INET6 2791 if (AF_INET6 == addr->raw.family) 2792 addr->raw.family = PR_AF_INET6; 2793 #endif 2247 2794 2248 PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); 2795 2249 PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); … … 2819 2273 } 2820 2274 #endif /* _PR_HAVE_SOCKADDR_LEN */ 2821 #ifdef _PR_INET6 2822 if (AF_INET6 == addr->raw.family) 2823 addr->raw.family = PR_AF_INET6; 2824 #endif 2275 2825 2276 PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); 2826 2277 PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); … … 3184 2635 }; 3185 2636 3186 static PRIOMethods _pr_udp_methods = {3187 PR_DESC_SOCKET_UDP,3188 pt_Close,3189 pt_SocketRead,3190 pt_SocketWrite,3191 pt_Available_s,3192 pt_Available64_s,3193 pt_Synch,3194 (PRSeekFN)_PR_InvalidInt,3195 (PRSeek64FN)_PR_InvalidInt64,3196 (PRFileInfoFN)_PR_InvalidStatus,3197 (PRFileInfo64FN)_PR_InvalidStatus,3198 pt_Writev,3199 pt_Connect,3200 (PRAcceptFN)_PR_InvalidDesc,3201 pt_Bind,3202 pt_Listen,3203 pt_Shutdown,3204 pt_Recv,3205 pt_Send,3206 pt_RecvFrom,3207 pt_SendTo,3208 pt_Poll,3209 (PRAcceptreadFN)_PR_InvalidInt,3210 (PRTransmitfileFN)_PR_InvalidInt,3211 pt_GetSockName,3212 pt_GetPeerName,3213 (PRReservedFN)_PR_InvalidInt,3214 (PRReservedFN)_PR_InvalidInt,3215 pt_GetSocketOption,3216 pt_SetSocketOption,3217 (PRSendfileFN)_PR_InvalidInt,3218 (PRConnectcontinueFN)_PR_InvalidStatus,3219 (PRReservedFN)_PR_InvalidInt,3220 (PRReservedFN)_PR_InvalidInt,3221 (PRReservedFN)_PR_InvalidInt,3222 (PRReservedFN)_PR_InvalidInt3223 };3224 3225 2637 static PRIOMethods _pr_socketpollfd_methods = { 3226 2638 (PRDescType) 0, … … 3337 2749 #endif 3338 2750 break; 3339 case PR_DESC_SOCKET_UDP:3340 fd->methods = PR_GetUDPMethods();3341 pt_MakeFdNonblock(osfd);3342 break;3343 2751 case PR_DESC_PIPE: 3344 2752 fd->methods = PR_GetPipeMethods(); … … 3367 2775 } /* PR_GetTCPMethods */ 3368 2776 3369 PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods(void)3370 {3371 return &_pr_udp_methods;3372 } /* PR_GetUDPMethods */3373 3374 2777 static const PRIOMethods* PR_GetSocketPollFdMethods(void) 3375 2778 { … … 3402 2805 } /* PR_AllocFileDesc */ 3403 2806 3404 #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE) 3405 PR_EXTERN(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd); 3406 #if defined(_PR_INET6_PROBE) 3407 PR_EXTERN(PRBool) _pr_ipv6_is_present; 3408 PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket() 3409 { 3410 PRInt32 osfd; 3411 3412 #if defined(DARWIN) 3413 /* 3414 * Disable IPv6 if Darwin version is less than 7.0.0 (OS X 10.3). IPv6 on 3415 * lesser versions is not ready for general use (see bug 222031). 3416 */ 3417 { 3418 struct utsname u; 3419 if (uname(&u) != 0 || atoi(u.release) < 7) 3420 return PR_FALSE; 3421 } 3422 #endif 3423 3424 /* 3425 * HP-UX only: HP-UX IPv6 Porting Guide (dated February 2001) 3426 * suggests that we call open("/dev/ip6", O_RDWR) to determine 3427 * whether IPv6 APIs and the IPv6 stack are on the system. 3428 * Our portable test below seems to work fine, so I am using it. 3429 */ 3430 osfd = socket(AF_INET6, SOCK_STREAM, 0); 3431 if (osfd != -1) { 3432 close(osfd); 3433 return PR_TRUE; 3434 } 3435 return PR_FALSE; 3436 } 3437 #endif /* _PR_INET6_PROBE */ 2807 #ifdef VBOX 2808 PRUintn _PR_NetAddrSize(const PRNetAddr* addr) 2809 { 2810 PRUintn addrsize; 2811 2812 #if defined(XP_UNIX) || defined(XP_OS2_EMX) 2813 if (AF_UNIX == addr->raw.family) 2814 addrsize = sizeof(addr->local); 2815 #endif 2816 else addrsize = 0; 2817 2818 return addrsize; 2819 } /* _PR_NetAddrSize */ 3438 2820 #endif 3439 2821 … … 3449 2831 if (pt_TestAbort()) return NULL; 3450 2832 3451 if (PF_INET != domain 3452 && PR_AF_INET6 != domain 3453 && PF_UNIX != domain) 2833 if (PF_UNIX != domain) 3454 2834 { 3455 2835 PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0); … … 3463 2843 return fd; 3464 2844 } 3465 #if defined(_PR_INET6_PROBE)3466 if (PR_AF_INET6 == domain) {3467 if (_pr_ipv6_is_present == PR_FALSE)3468 domain = AF_INET;3469 else3470 domain = AF_INET6;3471 }3472 #elif defined(_PR_INET6)3473 if (PR_AF_INET6 == domain)3474 domain = AF_INET6;3475 #else3476 if (PR_AF_INET6 == domain)3477 domain = AF_INET;3478 #endif3479 2845 3480 2846 osfd = socket(domain, type, proto); … … 3482 2848 else 3483 2849 { 3484 #ifdef DARWIN3485 if ((domain == AF_INET6) && _pr_ipv6_v6only_on_by_default)3486 {3487 int on = 0;3488 (void)setsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,3489 &on, sizeof(on));3490 }3491 #endif3492 2850 fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE); 3493 2851 if (fd == NULL) close(osfd); … … 3495 2853 #ifdef _PR_STRICT_ADDR_LEN 3496 2854 if (fd != NULL) fd->secret->af = domain; 3497 #endif3498 #if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)3499 if (fd != NULL) {3500 /*3501 * For platforms with no support for IPv63502 * create layered socket for IPv4-mapped IPv6 addresses3503 */3504 if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {3505 if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {3506 PR_Close(fd);3507 fd = NULL;3508 }3509 }3510 }3511 2855 #endif 3512 2856 return fd; … … 4335 3679 } /* PR_ReadDir */ 4336 3680 4337 PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void)4338 {4339 PRIntn domain = PF_INET;4340 4341 return PR_Socket(domain, SOCK_DGRAM, 0);4342 } /* PR_NewUDPSocket */4343 4344 PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket(void)4345 {4346 PRIntn domain = PF_INET;4347 4348 return PR_Socket(domain, SOCK_STREAM, 0);4349 } /* PR_NewTCPSocket */4350 4351 PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSocket(PRIntn af)4352 {4353 return PR_Socket(af, SOCK_DGRAM, 0);4354 } /* PR_NewUDPSocket */4355 4356 3681 PR_IMPLEMENT(PRFileDesc*) PR_OpenTCPSocket(PRIntn af) 4357 3682 { 4358 3683 return PR_Socket(af, SOCK_STREAM, 0); 4359 3684 } /* PR_NewTCPSocket */ 4360 4361 PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])4362 {4363 PRInt32 osfd[2];4364 4365 if (pt_TestAbort()) return PR_FAILURE;4366 4367 if (socketpair(AF_UNIX, SOCK_STREAM, 0, osfd) == -1) {4368 pt_MapError(_PR_MD_MAP_SOCKETPAIR_ERROR, errno);4369 return PR_FAILURE;4370 }4371 4372 fds[0] = pt_SetMethods(osfd[0], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);4373 if (fds[0] == NULL) {4374 close(osfd[0]);4375 close(osfd[1]);4376 return PR_FAILURE;4377 }4378 fds[1] = pt_SetMethods(osfd[1], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);4379 if (fds[1] == NULL) {4380 PR_Close(fds[0]);4381 close(osfd[1]);4382 return PR_FAILURE;4383 }4384 return PR_SUCCESS;4385 } /* PR_NewTCPSocketPair */4386 3685 4387 3686 PR_IMPLEMENT(PRStatus) PR_CreatePipe( -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptthread.c
r101777 r101793 966 966 _PR_ShutdownLinker(); 967 967 _PR_LogCleanup(); 968 _PR_CleanupNet();969 968 /* Close all the fd's before calling _PR_CleanupIO */ 970 969 _PR_CleanupIO();
Note:
See TracChangeset
for help on using the changeset viewer.