HTInetStatus("NETREAD"); HTAlert("Unexpected server disconnect."); CTRACE(tfp, "HTCopy: Unexpected server disconnect. Treating as completed.\n");
HTInetStatus("NETREAD"); HTAlert("Unexpected server disconnect."); CTRACE((tfp, "HTCopy: Unexpected server disconnect. Treating as completed.\n"));
PUBLIC int HTCopy ARGS4(	HTParentAnchor *,	anchor,	int,			file_number,	void*,			handle GCC_UNUSED,	HTStream*,		sink){    HTStreamClass targetClass;    int bytes;    int rv = 0;    /*	Push the data down the stream    */    targetClass = *(sink->isa); /* Copy pointers to procedures */    /*	Push binary from socket down sink    **    **	This operation could be put into a main event loop    */    HTReadProgress(bytes = 0, 0);    for (;;) {	int status;	if (LYCancelDownload) {	    LYCancelDownload = FALSE;	    (*targetClass._abort)(sink, NULL);	    rv = -1;	    goto finished;	}	if (HTCheckForInterrupt()) {	    _HTProgress (TRANSFER_INTERRUPTED);	    (*targetClass._abort)(sink, NULL);	    if (bytes)		rv = HT_INTERRUPTED;	    else		rv = -1;	    goto finished;	}#ifdef USE_SSL	if (handle)	    status = SSL_read((SSL *)handle, input_buffer, INPUT_BUFFER_SIZE);	else	    status = NETREAD(file_number, input_buffer, INPUT_BUFFER_SIZE);#else	status = NETREAD(file_number, input_buffer, INPUT_BUFFER_SIZE);#endif /* USE_SSL */	if (status <= 0) {	    if (status == 0) {		break;	    } else if (status == HT_INTERRUPTED) {		_HTProgress (TRANSFER_INTERRUPTED);		(*targetClass._abort)(sink, NULL);		if (bytes)		    rv = HT_INTERRUPTED;		else		    rv = -1;		goto finished;	    } else if (SOCKET_ERRNO == ENOTCONN ||		       SOCKET_ERRNO == ECONNRESET ||		       SOCKET_ERRNO == EPIPE) {		/*		 *  Arrrrgh, HTTP 0/1 compatibility problem, maybe.		 */		if (bytes <= 0) {		    /*		     *	Don't have any data, so let the calling		     *	function decide what to do about it. - FM		     */		    rv = -2;		    goto finished;		} else {#ifdef UNIX		   /*		    *  Treat what we've received already as the complete		    *  transmission, but not without giving the user		    *  an alert.  I don't know about all the different		    *  TCP stacks for VMS etc., so this is currently		    *  only for UNIX. - kw		    */		    HTInetStatus("NETREAD");		    HTAlert("Unexpected server disconnect.");		   CTRACE(tfp,	    "HTCopy: Unexpected server disconnect. Treating as completed.\n");		   status = 0;		   break;#else  /* !UNIX */		   /*		    *  Treat what we've gotten already		    *  as the complete transmission. - FM		    */		   CTRACE(tfp,	    "HTCopy: Unexpected server disconnect.  Treating as completed.\n");		   status = 0;		   break;#endif /* UNIX */		}#ifdef UNIX	    } else {		/* status < 0 and other errno */		/*		 *  Treat what we've received already as the complete		 *  transmission, but not without giving the user		 *  an alert.  I don't know about all the different		 *  TCP stacks for VMS etc., so this is currently		 *  only for UNIX. - kw		 */		HTInetStatus("NETREAD");		HTAlert("Unexpected read error.");		if (bytes) {		    (void)NETCLOSE(file_number);		    rv = HT_LOADED;		} else {		    (*targetClass._abort)(sink, NULL);		    rv = -1;		}		goto finished;#endif	    }	    break;	}#ifdef NOT_ASCII	{	    char * p;	    for (p = input_buffer; p < input_buffer+status; p++) {		*p = FROMASCII(*p);	    }	}#endif /* NOT_ASCII */	(*targetClass.put_block)(sink, input_buffer, status);	bytes += status;	HTReadProgress(bytes, anchor ? anchor->content_length : 0);	HTDisplayPartial();    } /* next bufferload */    _HTProgress(TRANSFER_COMPLETE);    (void)NETCLOSE(file_number);    rv = HT_LOADED;finished:    HTFinishDisplayPartial();    return(rv);}