21 #if defined(WIN32_VC) || defined(WIN64_VC) 36 _buffer = (
char *)PANDA_MALLOC_ARRAY(8192);
37 char *ebuf = _buffer + 8192;
38 char *mbuf = _buffer + 4096;
39 setg(_buffer, mbuf, mbuf);
48 char *m = b + (t - b) / 2;
61 PANDA_FREE_ARRAY(_buffer);
69 open(BioPtr *source) {
92 size_t n = pptr() - pbase();
93 if (downloader_cat.is_spam()) {
95 <<
"BioStreamBuf::overflow, " << n <<
" bytes\n";
98 size_t num_wrote = write_chars(pbase(), n);
100 if (num_wrote != n) {
125 size_t n = pptr() - pbase();
127 if (downloader_cat.is_spam() && n != 0) {
128 downloader_cat.spam()
129 <<
"BioStreamBuf::sync, " << n <<
" bytes\n";
132 size_t num_wrote = write_chars(pbase(), n);
135 if (num_wrote != n) {
149 if (gptr() >= egptr()) {
150 size_t buffer_size = egptr() - eback();
151 gbump(-(
int)buffer_size);
153 size_t num_bytes = buffer_size;
157 int read_count = BIO_read(*_source, gptr(), buffer_size);
158 thread_consider_yield();
160 if (read_count != (
int)num_bytes) {
162 if (read_count <= 0) {
165 #if defined(WIN32_VC) || defined(WIN64_VC) 166 int os_error = WSAGetLastError();
168 int os_error = errno;
174 _read_open = (BIO_should_retry(*_source) != 0);
179 if (!_read_open && os_error == 35) {
180 downloader_cat.warning() <<
"forcing retry to true again and _read_open to true\n";
181 BIO_set_retry_read(*_source);
186 downloader_cat.info()
187 <<
"Lost connection to " 188 << _source->get_server_name() <<
":" 189 << _source->get_port() <<
" (" << read_count <<
").\n";
190 OpenSSLWrapper::get_global_ptr()->notify_ssl_errors();
193 BIO_get_ssl(*_source, &ssl);
194 if (ssl !=
nullptr) {
195 downloader_cat.warning()
196 <<
"OpenSSL error code: " << SSL_get_error(ssl, read_count)
200 #if defined(WIN32_VC) || defined(WIN64_VC) 201 downloader_cat.warning()
202 <<
"Windows error code: " << os_error <<
"\n";
204 downloader_cat.warning()
205 <<
"Unix error code: " << os_error <<
"\n";
213 nassertr(read_count < (
int)num_bytes, EOF);
214 size_t delta = (int)num_bytes - read_count;
215 memmove(gptr() + delta, gptr(), read_count);
219 if (downloader_cat.is_spam()) {
220 downloader_cat.spam()
221 <<
"read " << read_count <<
" bytes from " << _source <<
"\n";
225 return (
unsigned char)*gptr();
233 size_t BioStreamBuf::
234 write_chars(
const char *start,
size_t length) {
236 size_t wrote_so_far = 0;
238 int write_count = BIO_write(*_source, start, length);
239 thread_consider_yield();
240 while (write_count != (
int)(length - wrote_so_far)) {
241 if (write_count <= 0) {
249 _write_open = (BIO_should_write(*_source) != 0 || BIO_should_retry(*_source) != 0);
256 BIO_get_fd(*_source, &fd);
258 downloader_cat.warning()
259 <<
"socket BIO has no file descriptor.\n";
261 if (downloader_cat.is_spam()) {
262 downloader_cat.spam()
263 <<
"waiting to write to BIO.\n";
265 #if defined(HAVE_THREADS) && defined(SIMPLE_THREADS) 274 select(fd + 1,
nullptr, &wset,
nullptr,
nullptr);
275 #endif // SIMPLE_THREADS 280 wrote_so_far += write_count;
281 if (downloader_cat.is_spam()) {
282 downloader_cat.spam()
283 <<
"wrote " << write_count <<
" bytes to " << _source <<
"\n";
288 write_count = BIO_write(*_source, start + wrote_so_far, length - wrote_so_far);
289 if (downloader_cat.is_spam()) {
290 downloader_cat.spam()
291 <<
"continued, wrote " << write_count <<
" bytes.\n";
293 thread_consider_yield();
295 if (downloader_cat.is_spam()) {
296 downloader_cat.spam()
297 <<
"wrote " << write_count <<
" bytes to " << _source <<
"\n";
304 #endif // HAVE_OPENSSL PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.