<commit_before>#define _POSIX_SOURCE

#include "condor_common.h"
#include "condor_constants.h"
#include "condor_io.h"
#include "condor_debug.h"


unsigned long num_created = 0;
unsigned long num_deleted = 0;



void
sanity_check()
{
	dprintf(D_ALWAYS, "IO: Buffer management:\n");
	dprintf(D_ALWAYS, "IO:     created: %d\n", num_created);
	dprintf(D_ALWAYS, "IO:     deleted: %d\n\n", num_deleted);
}


Buf::Buf(
	int	sz
	)
{
	_dta = new char[sz];
	_dta_maxsz = sz;
	_dta_sz = 0;
	_dta_pt = 0;
	_next = NULL;
	num_created++;
}


Buf::~Buf()
{
	if (_dta) delete [] _dta;
	num_deleted++;
}



int Buf::write(
	SOCKET	sockd,
	int		sz,
	int		timeout
	)
{
	int	nw;
	int nwo;
	unsigned int start_time, curr_time;

	if (sz < 0 || sz > num_untouched()) sz = num_untouched();

	if ( timeout > 0 ) {
		start_time = time(NULL);
		curr_time = start_time;
	}

	for(nw=0;nw < sz;) {
		if (timeout > 0) {
			struct timeval	timer;
			fd_set			writefds;
			int				nfds=0, nfound;

			if ( curr_time == 0 )
				curr_time = time(NULL);
			if ( start_time + timeout > curr_time ) {
				timer.tv_sec = (start_time + timeout) - curr_time;
			} else {
				dprintf(D_ALWAYS,"timeout reading in Buf::read()\n");
				return -1;
			}
			curr_time = 0;	// so we call time() next time around
			timer.tv_usec = 0;
	#if !defined(WIN32) // nfds is ignored on WIN32
			nfds = sockd + 1;
	#endif
			FD_ZERO( &writefds );
			FD_SET( sockd, &writefds );

			nfound = select( nfds, 0, &writefds, 0, &timer );

			switch(nfound) {
			case 0:
				dprintf(D_ALWAYS,"select timed out in Buf::write()\n");
				return -1;
				break;
			case 1:
				break;
			default:
				dprintf( D_ALWAYS, "select returns %d, send failed\n",
					nfound );
				return -1;
				break;
			}
		}

		nwo = send(sockd, &_dta[num_touched()], sz-nw, 0);
		if (nwo <= 0) return -1;

		nw += nwo;<commit_msg>fixed my previous checkin<commit_after>#define _POSIX_SOURCE

#include "condor_common.h"
#include "condor_constants.h"
#include "condor_io.h"
#include "condor_debug.h"


unsigned long num_created = 0;
unsigned long num_deleted = 0;



void
sanity_check()
{
	dprintf(D_ALWAYS, "IO: Buffer management:\n");
	dprintf(D_ALWAYS, "IO:     created: %d\n", num_created);
	dprintf(D_ALWAYS, "IO:     deleted: %d\n\n", num_deleted);
}


Buf::Buf(
	int	sz
	)
{
	_dta = new char[sz];
	_dta_maxsz = sz;
	_dta_sz = 0;
	_dta_pt = 0;
	_next = NULL;
	num_created++;
}


Buf::~Buf()
{
	if (_dta) delete [] _dta;
	num_deleted++;
}



int Buf::write(
	SOCKET	sockd,
	int		sz,
	int		timeout
	)
{
	int	nw;
	int nwo;
	unsigned int start_time, curr_time;

	if (sz < 0 || sz > num_untouched()) sz = num_untouched();

	if ( timeout > 0 ) {
		start_time = time(NULL);
		curr_time = start_time;
	}

	for(nw=0;nw < sz;) {
		if (timeout > 0) {
			struct timeval	timer;
			fd_set			writefds;
			int				nfds=0, nfound;

			if ( curr_time == 0 )
				curr_time = time(NULL);
			if ( start_time + timeout > curr_time ) {
				timer.tv_sec = (start_time + timeout) - curr_time;
			} else {
				dprintf(D_ALWAYS,"timeout reading in Buf::write()\n");
				return -1;
			}
			curr_time = 0;	// so we call time() next time around
			timer.tv_usec = 0;
	#if !defined(WIN32) // nfds is ignored on WIN32
			nfds = sockd + 1;
	#endif
			FD_ZERO( &writefds );
			FD_SET( sockd, &writefds );

			nfound = select( nfds, 0, &writefds, 0, &timer );

			switch(nfound) {
			case 0:
				dprintf(D_ALWAYS,"select timed out in Buf::write()\n");
				return -1;
				break;
			case 1:
				break;
			default:
				dprintf( D_ALWAYS, "select returns %d, send failed\n",
					nfound );
				return -1;
				break;
			}
		}

		nwo = send(sockd, &_dta[num_touched()+nw], sz-nw, 0);
		if (nwo <= 0) return -1;

		nw += nwo;
{'fraction_non_alphanumeric': 0.1507034632034632, 'fraction_numerical': 0.01461038961038961, 'mean_word_length': 3.0448577680525166, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6683556', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1577, 'n_words': 382}