<commit_before>/*
 *  SMTP.cpp
 *  OpenLieroX
 *
 *  Created by <NAME> on 19.10.09.
 *  Code under LGPL.
 *
 */

#include "Networking.h"
#include "SMTP.h"
#include "Debug.h"
#include "Timer.h"

struct SmtpClient::Handler {
	NetworkSocket sock;
};

static bool SmtpClient_wait(NetworkSocket& sock, const std::string& expectedstart) {
	char c = 0;
	int r = 0;
	std::string line;
	AbsTime startTime = GetTime();
	while((r = sock.Read(&c, 1)) >= 0) {
		if(r == 0) {
			if(GetTime() - startTime >= TimeDiff(float(10.0))) {
				errors << "SMTP: timeout while waiting for " << expectedstart << endl;
				return false;
			}
			SDL_Delay(10);
			continue;
		}
		
		if(c == '\n') break;
		line += c;
	}
	if(r < 0) {
		errors << "SMTP: error while waiting for " << expectedstart << endl;
		return false;
	}
	
	if(!subStrEqual(line, expectedstart, expectedstart.size())) {
		errors << "SMTP: expected was " << expectedstart << " but we got '" << line << "'" << endl;
		return false;
	}
	
	return true;
}

static bool SmtpClient_write(NetworkSocket& sock, const std::string& line) {
	if(sock.Write(line + "\n") < int(line.size() + 1)) {
		errors << "SMTP: error while writing " << line << endl;
		return false;
	}
	return true;
}

static bool SmtpClient_writeAndWait(NetworkSocket& sock, const std::string& line, const std::string& expectedanswer) {
	if(!SmtpClient_write(sock, line)) return false;
	return SmtpClient_wait(sock, expectedanswer);
}

bool SmtpClient::connect() {<commit_msg>removed too short timeout (just wait until there is something; if there is an error, it would break anyway); correct write on socket<commit_after>/*
 *  SMTP.cpp
 *  OpenLieroX
 *
 *  Created by <NAME> on 19.10.09.
 *  Code under LGPL.
 *
 */

#include "Networking.h"
#include "SMTP.h"
#include "Debug.h"
#include "Timer.h"

struct SmtpClient::Handler {
	NetworkSocket sock;
};

static bool SmtpClient_wait(NetworkSocket& sock, const std::string& expectedstart) {
	char c = 0;
	int r = 0;
	std::string line;
	AbsTime startTime = GetTime();
	while((r = sock.Read(&c, 1)) >= 0) {
		if(r == 0) {
			SDL_Delay(10);
			continue;
		}
		
		if(c == '\n') break;
		line += c;
	}
	if(r < 0) {
		errors << "SMTP: error while waiting for " << expectedstart << endl;
		return false;
	}
	
	if(!subStrEqual(line, expectedstart, expectedstart.size())) {
		errors << "SMTP: expected was " << expectedstart << " but we got '" << line << "'" << endl;
		return false;
	}
	
	return true;
}

static bool writeOnSocket(NetworkSocket& sock, std::string buf) {
	while(buf.size() > 0) {
		int ret = sock.Write(buf);
		if(ret < 0) return false;
		buf.erase(0, ret);
	}
	return true;
}

static bool SmtpClient_write(NetworkSocket& sock, const std::string& line) {
	if(!writeOnSocket(sock, line + "\n")) {
		errors << "SMTP: error while writing " << line << endl;
		return false;
	}
	return true;
}

static bool SmtpClient_writeAndWait(NetworkSocket& sock, const std::string& line, const std::string& expectedanswer) {
	if(!SmtpClient_write(sock, line)) return false;
	return SmtpClient_wait(sock, expectedanswer);
}

bool SmtpClient::connect() {
{'fraction_non_alphanumeric': 0.15809893307468478, 'fraction_numerical': 0.011315874555447785, 'mean_word_length': 3.990322580645161, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 9, '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': '2182513', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1091, 'n_words': 301}