<commit_before>#include <errno.h>
#include <unistd.h>
#include <libtorque/buffers.h>
#include <libtorque/libtorque.h>

static inline int
callback(libtorque_rxbuf *rxb,int fd,libtorque_cbctx *cbctx,void *cbstate){
	if(rxb->bufoff - rxb->bufate){
		return ((const libtorquercb)cbctx->cbstate)(fd,cbctx,cbstate);
	}
	return 0;
}

int buffered_rxfxn(int fd,libtorque_cbctx *cbctx,void *cbstate){
	libtorque_rxbuf *rxb = cbctx->rxbuf;
	int r;

	for( ; ; ){
		if(rxb->buftot - rxb->bufoff == 0){
			if(callback(rxb,fd,cbctx,cbstate)){
				break;
			}
			// FIXME if no space was cleared, grow that fucker
		}
		if((r = read(fd,rxb->buffer + rxb->bufate,rxb->buftot - rxb->bufoff)) > 0){
			rxb->bufoff += r;
		}else if(r == 0){
			if(callback(rxb,fd,cbctx,cbstate) == 0){
				close(fd);
			}
			return 0;
		}else if(errno == EAGAIN){<commit_msg>always break out + close on callback fail<commit_after>#include <errno.h>
#include <unistd.h>
#include <libtorque/buffers.h>
#include <libtorque/libtorque.h>

static inline int
callback(libtorque_rxbuf *rxb,int fd,libtorque_cbctx *cbctx,void *cbstate){
	if(rxb->bufoff - rxb->bufate){
		return ((const libtorquercb)cbctx->cbstate)(fd,cbctx,cbstate);
	}
	return 0;
}

int buffered_rxfxn(int fd,libtorque_cbctx *cbctx,void *cbstate){
	libtorque_rxbuf *rxb = cbctx->rxbuf;
	int r;

	for( ; ; ){
		if(rxb->buftot - rxb->bufoff == 0){
			if(callback(rxb,fd,cbctx,cbstate)){
				break;
			}
			// FIXME if no space was cleared, grow that fucker
		}
		if((r = read(fd,rxb->buffer + rxb->bufate,rxb->buftot - rxb->bufoff)) > 0){
			rxb->bufoff += r;
		}else if(r == 0){
			if(callback(rxb,fd,cbctx,cbstate)){
				break;
			}
			return 0; // FIXME
		}else if(errno == EAGAIN){
{'fraction_non_alphanumeric': 0.17174677608440797, 'fraction_numerical': 0.006447831184056272, 'mean_word_length': 4.236196319018405, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '2451813', 'n_tokens_mistral': 798, 'n_tokens_neox': 727, 'n_words': 137}