Example #1
0
int Cogg_file::decode(Cvirtual_audio& audio)
{
	int error = 0;
	OggVorbis_File vf;
	seek(0);
	if (ov_open_callbacks(this, &vf, NULL, 0, cbs) < 0) 
		error = 0x100;
	else
	{		
		vorbis_info* vi = ov_info(&vf, -1);
		Cvirtual_binary b;
		char* w = reinterpret_cast<char*>(b.write_start(vi->channels * ov_pcm_total(&vf, -1) << 1));
		while (!error)
		{
			int current_section;
			int cb_read = ov_read(&vf, w, b.size(), 0, 2, 1, &current_section);
			if (!cb_read) 
				break;
			else if (cb_read < 0) 
				error = 1;
			else 
				w += cb_read;
		}
		if (!error)
			audio.load(b, b.size() / (vi->channels << 1), vi->rate, 2, vi->channels);
		ov_clear(&vf);
	}
	return error;
}
Example #2
0
Cvirtual_binary Cxif_key::vdata(bool fast) const
{
	Cvirtual_binary d;
	int size = get_size();
	int external_size = get_external_size();
	if (fast)
	{
		t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + size + external_size));
		header.id = file_id;
		header.version = file_version_fast;
		header.size_uncompressed = 0;
		header.size_compressed = size;
		header.size_external = external_size;
		byte* w = d.data_edit() + sizeof(t_xif_header_fast);
		save(w);
		external_save(w);
		assert(d.data_end() == w);
		return d;
	}
	Cvirtual_binary s;
	byte* w = s.write_start(size);
	save(w);
	unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12;
	t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + cb_d + external_size));
	compress(d.data_edit() + sizeof(t_xif_header_fast), &cb_d, s.data(), s.size());
	w = d.data_edit() + sizeof(t_xif_header_fast) + cb_d;
	external_save(w);
	header.id = file_id;
	header.version = file_version_fast;
	header.size_uncompressed = size;
	header.size_compressed = cb_d;
	header.size_external = external_size;
	d.size(sizeof(t_xif_header_fast) + cb_d + external_size);
	return d;
}
Example #3
0
int Cmix_edit::insert(const string& name, Cvirtual_binary d)
{
	mix_database::add_name(m_game, name, "-");
	int offset = new_block(d.size());
	m_f.seek(offset);
	int error = m_f.write(d);
	if (!error)
		m_index[id(name)] = t_mix_index_entry(id(name), offset, d.size());
	return error;
}
Example #4
0
int Cmerkle_tree::load(const Cvirtual_binary& v)
{
	if (v.size() % 21)
		return 1;
	m_size = v.size() / 21;
	for (int i = 1; i < m_size; i <<= 1)
		m_size -= i;
	if (m_size)
		m_d = v;
	return 0;
}
Example #5
0
int Cmix_edit::write_index()
{
	{
		Cxcc_lmd_file_write lmd_fw;
		for (auto& i : m_index)
		{
			string name = mix_database::get_name(m_game, i.second.id);
			if (!name.empty())
				lmd_fw.add_fname(name);
		}
		insert("local mix database.dat", lmd_fw.write(m_game));
	}
	Cvirtual_binary d;
	byte* w = d.write_start(cb_header(m_index.size()));
	*reinterpret_cast<__int32*>(w) = 0;
	w += 4;
	t_mix_header& header = *reinterpret_cast<t_mix_header*>(w);
	header.c_files = m_index.size();
	w += sizeof(t_mix_header);
	{
		t_block_map block_map = Cmix_edit::block_map();
		for (auto& i : block_map)
		{
			if (i.second->offset < d.size())
			{
				int offset = new_block(i.second->size);
				int error = copy_block(m_f, i.second->offset, m_f, offset, i.second->size);
				if (error)
					return error;
				i.second->offset = offset;
			}
		}
	}
	int total_size = d.size();
	t_mix_index_entry* index = reinterpret_cast<t_mix_index_entry*>(w);
	for (auto& i : m_index)
	{
		index->id = i.first;
		index->offset = i.second.offset - d.size();
		index->size = i.second.size;
		index++;
		total_size = max(total_size, i.second.offset + i.second.size);
	}	
	m_f.seek(total_size);
	m_f.set_eof();
	header.size = m_f.size() - d.size();
	m_f.seek(0);
	return m_f.write(d);
}
Example #6
0
void Cdlg_login::add_game(const string& reg_key, ::t_game game, int gsku)
{
	Creg_key key;
	string serial;
	if (ERROR_SUCCESS == key.open(HKEY_LOCAL_MACHINE, reg_key, KEY_READ))
		key.query_value("Serial", serial);
	if (serial.size() == 22)
	{
		Cvirtual_binary s;
		s.load(xcc_dirs::get_dir(game) + "woldata.key");
		for (int i = 0, j = 0; i < s.size(); i++, j++)
		{
			if (j == serial.length())
				j = 0;
			serial[j] = (262 - s.data()[i] + serial[j]) % 10 + '0';
		}
	}
	else
		serial.clear();
	t_game e;
	e.gsku = gsku;
	e.serial = serial;
	m_game.SetItemData(m_game.AddString(game_name[game]), m_games.size());
	m_games.push_back(e);			
}
Example #7
0
Cvirtual_binary Cbig_file_write::write()
{
	int cb_header = sizeof(t_big_header);
	int cb_d = sizeof(t_big_header);
	for (auto& i : m_index)
	{
		cb_header += sizeof(t_big_index_entry) + i.first.length() + 1;
		cb_d += sizeof(t_big_index_entry) + i.first.length() + 1 + i.second.size();
	}
	Cvirtual_binary d;
	byte* w = d.write_start(cb_d);
	t_big_header& header = *reinterpret_cast<t_big_header*>(w);
	header.id = big_id;
	header.size = d.size();
	header.mc_files = reverse(m_index.size());
	header.mcb_header = reverse(cb_header);
	byte* w2 = w + cb_header;
	w += sizeof(t_big_header);
	for (auto& i : m_index)
	{
		t_big_index_entry& e = *reinterpret_cast<t_big_index_entry*>(w);
		e.offset = reverse(w2 - d.data());
		e.size = reverse(i.second.size());
		w += sizeof(t_big_index_entry);
		memcpy(w, i.first.c_str(), i.first.length() + 1);
		w += i.first.length() + 1;
		w2 += i.second.read(w2);
	}
	assert(w2 == d.data_end());
	return d;
}
Example #8
0
Cvirtual_binary Cbvalue::read() const
{
	Cvirtual_binary d;
	int cb_d = read(d.write_start(pre_read()));
	assert(cb_d == d.size());
	return d;
}
Example #9
0
Cvirtual_binary shp_file_write(const byte* s, int cx, int cy, int c_images)
{
    Cvirtual_binary d;
    const byte* r = s;
    byte* w = d.write_start(sizeof(t_shp_ts_header) + (sizeof(t_shp_ts_image_header) + cx * cy) * c_images);
    t_shp_header& header = *reinterpret_cast<t_shp_header*>(w);
    header.c_images = c_images;
    header.unknown1 = 0;
    header.unknown2 = 0;
    header.cx = cx;
    header.cy = cy;
    header.unknown3 = 0;
    w += sizeof(t_shp_header);
    int* index = reinterpret_cast<int*>(w);
    w += 8 * (c_images + 2);
    for (int i = 0; i < c_images; i++)
    {
        *index++ = 0x80000000 | w - d.data();
        *index++ = 0;
        w += encode80(r, w, cx * cy);
        r += cx * cy;
    }
    *index++ = w - d.data();
    *index++ = 0;
    *index++ = 0;
    *index++ = 0;
    d.size(w - d.data());
    return d;
}
Example #10
0
Cvirtual_binary Cxif_key::export_bz() const
{
	Cvirtual_binary d;
	int size = get_size();
	int external_size = get_external_size();
	Cvirtual_binary s;
	byte* w = s.write_start(size);
	save(w);
	unsigned int cb_d = s.size() + (s.size() + 99) / 100 + 600;
	t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + cb_d + external_size));
	if (BZ_OK != BZ2_bzBuffToBuffCompress(reinterpret_cast<char*>(d.data_edit() + sizeof(t_xif_header_fast)), &cb_d, const_cast<char*>(reinterpret_cast<const char*>(s.data())), s.size(), 9, 0, 0))
		return Cvirtual_binary();
	w = d.data_edit() + sizeof(t_xif_header_fast) + cb_d;
	external_save(w);
	header.id = file_id;
	header.version = file_version_fast;
	header.size_uncompressed = size;
	header.size_compressed = cb_d;
	header.size_external = external_size;
	d.size(sizeof(t_xif_header_fast) + cb_d + external_size);
	return d;
}
Example #11
0
void Cbt_tracker_accounts::load(const Cvirtual_binary& s)
{
	clear();
	if (s.size() < 4)
		return;
	Cstream_reader r(s);
	for (int count = r.read_int(4); count--; )
	{
		std::string tracker = r.read_string();
		std::string name = r.read_string();
		std::string pass = r.read_string();
		push_back(Cbt_tracker_account(tracker, name, pass));
	}
}
Example #12
0
int mix_database::load()
{
	if (!td_list.empty() || !ra_list.empty() || !ts_list.empty())
		return 0;
	Cvirtual_binary f;
	if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16)
		return 1;
	const char* data = reinterpret_cast<const char*>(f.data());
	read_list(game_td, data);
	read_list(game_ra, data);
	read_list(game_ts, data);
	read_list(game_ra2, data);
	if (0)
	{
		ofstream log_f("c:\\log.txt");
		for (auto& i : ts_list)
			log_f << i.second.name << '\t' << i.second.description << endl;
	}
	return 0;
	char name[12] = "scg00ea.bin";
	const char char1[] = "bgjm";
	const char char2[] = "ew";
	const char char3[] = "abc";
	for (int i = 0; i < 2; i++)
	{
		if (i)
			strcpy(name + 8, "ini");
		for (int j = 0; j < 4; j++)
		{
			name[2] = char1[j];
			for (int k = 0; k < 100; k++)
			{
				memcpy(name + 3, nwzl(2, k).c_str(), 2);
				for (int l = 0; l < 2; l++)
				{
					name[5] = char2[l];
					for (int m = 0; m < 3; m++)
					{
						name[6] = char3[m];
						mix_database::add_name(game_td, name, "");
						mix_database::add_name(game_ra, name, "");
						mix_database::add_name(game_ts, name, "");
					}
				}
			}
		}
	}
	return 0;
}
Example #13
0
Cvirtual_binary vxl_file_write(const Cxif_key& s)
{
	Cvirtual_binary d;
	byte* w = d.write_start(1 << 20);
	const Cxif_key& header_key = s.open_key_read(vi_header);
	const Cxif_key& body_key = s.open_key_read(vi_body);
	int c_sections = body_key.c_keys();
	int* span_start_list_ofs = new int[c_sections];
	int* span_end_list_ofs = new int[c_sections];
	int* span_data_ofs = new int[c_sections];
	t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w);
	strcpy(header.id, vxl_id);
	header.one = 1;
	header.c_section_headers = c_sections;
	header.c_section_tailers = c_sections;
	header.unknown = 0x1f10;
	const Cxif_key& palet_key = header_key.open_key_read(vi_palet);
	int i;
	for (i = 0; i < 256; i++)
	{
		const Cxif_key& palet_entry_key = palet_key.open_key_read(i);
		header.palet[i].r = palet_entry_key.get_value_int(vi_red);
		header.palet[i].g = palet_entry_key.get_value_int(vi_green);
		header.palet[i].b = palet_entry_key.get_value_int(vi_blue);
	}
	w += sizeof(t_vxl_header);
	for (i = 0; i < c_sections; i++)
	{
		const Cxif_key& section_key = body_key.open_key_read(i);
		const Cxif_key& section_header_key = section_key.open_key_read(vi_header);
		t_vxl_section_header& section_header = *reinterpret_cast<t_vxl_section_header*>(w);
		strcpy(section_header.id, section_header_key.get_value_string(vi_id).c_str());
		section_header.section_i = i;
		section_header.one = 1;
		section_header.zero = 0;
		w += sizeof(t_vxl_section_header);
	}
	byte* body_start = w;
	for (i = 0; i < c_sections; i++)
	{
		const Cxif_key& section_key = body_key.open_key_read(i);
		const Cxif_key& section_body_key = section_key.open_key_read(vi_body);
		const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer);
		const int cx = section_tailer_key.get_value_int(vi_cx);
		const int cy = section_tailer_key.get_value_int(vi_cy);
		const int cz = section_tailer_key.get_value_int(vi_cz);
		__int32* span_start_list = reinterpret_cast<__int32*>(w);
		span_start_list_ofs[i] = w - body_start;
		w += 4 * cx * cy;
		__int32* span_end_list = reinterpret_cast<__int32*>(w);
		span_end_list_ofs[i] = w - body_start;
		w += 4 * cx * cy;
		byte* span_data_start = w;
		span_data_ofs[i] = w - body_start;
		int span_i = 0;
		for (int y = 0; y < cy; y++)
		{
			const Cxif_key& yi = section_body_key.open_key_read(y);
			for (int x = 0; x < cx; x++)
			{
				byte* span_start = w;
				const Cxif_key& xi = yi.open_key_read(x);
				int z = 0;
				for (auto& i : xi.m_keys)
				{
					int z_inc = i.first - z;
					z = i.first + 1;
					*w++ = z_inc;
					*w++ = 1;
					*w++ = i.second.get_value_int(vi_color);
					*w++ = i.second.get_value_int(vi_surface_normal);
					*w++ = 1;
				}
				if (span_start == w)
				{
					span_start_list[span_i] = -1;
					span_end_list[span_i] = -1;
				}
				else
				{
					if (z != cz)
					{
						*w++ = cz - z;
						*w++ = 0;
						*w++ = 0;
					}
					span_start_list[span_i] = span_start - span_data_start;
					span_end_list[span_i] = w - span_data_start - 1;
				}
				span_i++;
			}
		}
	}
	header.size = w - body_start;
	for (i = 0; i < c_sections; i++)
	{
		const Cxif_key& section_key = body_key.open_key_read(i);
		const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer);
		t_vxl_section_tailer& section_tailer = *reinterpret_cast<t_vxl_section_tailer*>(w);

		section_tailer.span_start_ofs = span_start_list_ofs[i];
		section_tailer.span_end_ofs = span_end_list_ofs[i];
		section_tailer.span_data_ofs = span_data_ofs[i];
		section_tailer.scale = 0;
		for (int ty = 0; ty < 3; ty++)
		{
			for (int tx = 0; tx < 4; tx++)
				section_tailer.transform[ty][tx] = 0;
		}
		section_tailer.x_min_scale = section_tailer_key.get_value_int(vi_x_min) / 1000000.0;
		section_tailer.y_min_scale = section_tailer_key.get_value_int(vi_y_min) / 1000000.0;
		section_tailer.z_min_scale = section_tailer_key.get_value_int(vi_z_min) / 1000000.0;
		section_tailer.x_max_scale = section_tailer_key.get_value_int(vi_x_max) / 1000000.0;
		section_tailer.y_max_scale = section_tailer_key.get_value_int(vi_y_max) / 1000000.0;
		section_tailer.z_max_scale = section_tailer_key.get_value_int(vi_z_max) / 1000000.0;
		section_tailer.cx = section_tailer_key.get_value_int(vi_cx);
		section_tailer.cy = section_tailer_key.get_value_int(vi_cy);
		section_tailer.cz = section_tailer_key.get_value_int(vi_cz);
		section_tailer.unknown = 2;
		w += sizeof(t_vxl_section_tailer);
	}
	delete[] span_data_ofs;
	delete[] span_end_list_ofs;
	delete[] span_start_list_ofs;
	d.size(w - d.data());
	return d;
}
Example #14
0
Cvirtual_binary vxl_decode4(const byte* s, int cb_d)
{
	Cvirtual_binary d;
	const byte* r = s;
	const t_vxl4_header& s_header = *reinterpret_cast<const t_vxl4_header*>(r);
	const int c_sections = s_header.c_sections;
	r += sizeof(t_vxl4_header);
	byte* w = d.write_start(cb_d ? cb_d : 1 << 20);
	t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w);
	strcpy(header.id, vxl_id);
	header.one = 1;
	header.c_section_headers = c_sections;
	header.c_section_tailers = c_sections;
	header.unknown = 0x1f10;
	w += sizeof(t_vxl_header);
	t_vxl_section_header* d_section_header = reinterpret_cast<t_vxl_section_header*>(w);
	t_vxl_section_tailer* section_tailer = new t_vxl_section_tailer[c_sections];
	w += sizeof(t_vxl_section_header) * c_sections;
	byte* body_start = w;
	for (int i = 0; i < c_sections; i++)
	{
		const t_vxl4_section_header& section_header = *reinterpret_cast<const t_vxl4_section_header*>(r);
		const int cx = section_header.cx;
		const int cy = section_header.cy;
		const int cz = section_header.cz;
		strcpy(d_section_header->id, section_header.id);
		d_section_header->section_i = section_header.section_i;
		d_section_header->one = 1;
		d_section_header->zero = 0;
		d_section_header++;
		__int32* span_start_list = reinterpret_cast<__int32*>(w);
		section_tailer[i].span_start_ofs = w - body_start;
		w += 4 * cx * cy;
		__int32* span_end_list = reinterpret_cast<__int32*>(w);
		section_tailer[i].span_end_ofs = w - body_start;
		w += 4 * cx * cy;
		section_tailer[i].span_data_ofs = w - body_start;
		section_tailer[i].scale = section_header.scale;
		section_tailer[i].x_min_scale = section_header.x_min_scale;
		section_tailer[i].y_min_scale = section_header.y_min_scale;
		section_tailer[i].z_min_scale = section_header.z_min_scale;
		section_tailer[i].x_max_scale = section_header.x_max_scale;
		section_tailer[i].y_max_scale = section_header.y_max_scale;
		section_tailer[i].z_max_scale = section_header.z_max_scale;
		section_tailer[i].cx = section_header.cx;
		section_tailer[i].cy = section_header.cy;
		section_tailer[i].cz = section_header.cz;
		section_tailer[i].unknown = section_header.unknown;
		r += sizeof(t_vxl4_section_header);
		byte* span_data_start = w;
		for (int j = 0; j < cx * cy; j++)
		{
			byte* span_start = w;
			int z = 0;
			while (z < cz)
			{
				int z_inc = *r++;
				if (z_inc == cz)
					break;
				z += *w++ = z_inc;
				int count = *w++ = *r++;
				int c = count;
				while (c--)
				{
					*w++ = *r++;
					*w++ = *r++;
					z++;
				}
				*w++ = count;
			}
			if (span_start == w)
			{
				span_start_list[j] = -1;
				span_end_list[j] = -1;
			}
			else
			{
				span_start_list[j] = span_start - span_data_start;
				span_end_list[j] = w - span_data_start - 1;
			}
		}
	}
	header.size = w - body_start;
	memcpy(w, section_tailer, sizeof(t_vxl_section_tailer) * c_sections);
	delete[] section_tailer;
	w += sizeof(t_vxl_section_tailer) * c_sections;
	assert(!cb_d || d.size() == w - d.data());
	return cb_d ? d : Cvirtual_binary(d.data(), w - d.data());
}
Example #15
0
static Cvirtual_binary gzip(const Cvirtual_binary& s)
{
	Cvirtual_binary d = xcc_z::gzip(s);
	return d.size() < s.size() ? d : s;
}
Example #16
0
static Cvirtual_binary gzip(const Cvirtual_binary& s)
{
	// gzip input if it results in a smaller size
	Cvirtual_binary d = xcc_z::gzip(s);
	return d.size() < s.size() ? d : s;
}
Example #17
0
int Cbvalue::write(const Cvirtual_binary& v)
{
	return write(v, v.size());
}
Example #18
0
void Cconnection::read(const std::string& v)
{
#ifndef NDEBUG
	std::cout << v << std::endl;
#endif
	if (m_server->config().m_log_access)
	{
		static std::ofstream f("xbt_tracker_raw.log");
		f << m_server->time() << '\t' << inet_ntoa(m_a.sin_addr) << '\t' << ntohs(m_a.sin_port) << '\t' << v << std::endl;
	}
	Ctracker_input ti;
	size_t e = v.find('?');
	if (e == std::string::npos)
		e = v.size();
	else
	{
		size_t a = e + 1;
		size_t b = v.find(' ', a);
		if (b == std::string::npos)
			return;
		while (a < b)
		{
			size_t c = v.find('=', a);
			if (c++ == std::string::npos)
				break;
			size_t d = v.find_first_of(" &", c);
			if (d == std::string::npos)
				break;
			ti.set(v.substr(a, c - a - 1), uri_decode(v.substr(c, d - c)));
			a = d + 1;
		}
	}
	if (!ti.m_ipa || !is_private_ipa(m_a.sin_addr.s_addr))
		ti.m_ipa = m_a.sin_addr.s_addr;
	std::string torrent_pass0;
	size_t a = 4;
	if (a < e && v[a] == '/')
	{
		a++;
		if (a + 1 < e && v[a + 1] == '/')
			a += 2;
		if (a + 32 < e && v[a + 32] == '/')
		{
			torrent_pass0 = v.substr(a, 32);
			a += 33;
			if (a + 40 < e && v[a + 40] == '/')
				a += 41;
		}
	}
	std::string h = "HTTP/1.0 200 OK\r\n";
	Cvirtual_binary s;
	bool gzip = true;
	switch (a < v.size() ? v[a] : 0)
	{
	case 'a':
		if (!ti.valid())
			break;
		gzip = false;
		if (0)
			s = Cbvalue().d(bts_failure_reason, bts_banned_client).read();
		else
		{
			std::string error = m_server->insert_peer(ti, false, m_server->find_user_by_torrent_pass(torrent_pass0, ti.m_info_hash));
			s = error.empty() ? m_server->select_peers(ti) : Cbvalue().d(bts_failure_reason, error).read();
		}
		break;
	case 'd':
		if (m_server->config().m_debug)
		{
			gzip = m_server->config().m_gzip_debug;
			h += "Content-Type: text/html; charset=us-ascii\r\n";
			s = Cvirtual_binary(m_server->debug(ti));
		}
		break;
	case 's':
		if (v.size() >= 7 && v[6] == 't')
		{
			gzip = m_server->config().m_gzip_debug;
			h += "Content-Type: text/html; charset=us-ascii\r\n";
			s = Cvirtual_binary(m_server->statistics());
		}
		else if (m_server->config().m_full_scrape || ti.m_compact || !ti.m_info_hash.empty())
		{
			gzip = m_server->config().m_gzip_scrape && !ti.m_compact && ti.m_info_hash.empty();
			s = m_server->scrape(ti);
		}
		break;
	}
	if (s.empty())
	{
		if (!ti.m_peer_id.empty() || m_server->config().m_redirect_url.empty())
			h = "HTTP/1.0 404 Not Found\r\n";
		else
		{
			h = "HTTP/1.0 302 Found\r\n"
				"Location: " + m_server->config().m_redirect_url + (ti.m_info_hash.empty() ? "" : "?info_hash=" + uri_encode(ti.m_info_hash)) + "\r\n";
		}
	}
	else if (gzip)
	{
		Cvirtual_binary s2 = xcc_z::gzip(s);
#ifndef NDEBUG
		static std::ofstream f("xbt_tracker_gzip.log");
		f << m_server->time() << '\t' << v[5] << '\t' << s.size() << '\t' << s2.size() << std::endl;
#endif
		if (s2.size() + 24 < s.size())
		{
			h += "Content-Encoding: gzip\r\n";
			s = s2;
		}
	}
	h += "\r\n";
#ifdef WIN32
	m_write_b.resize(h.size() + s.size());
	memcpy(m_write_b.data_edit(), h.data(), h.size());
	s.read(m_write_b.data_edit() + h.size());
	int r = m_s.send(m_write_b);
#else
	boost::array<iovec, 2> d;
	d[0].iov_base = const_cast<char*>(h.data());
	d[0].iov_len = h.size();
	d[1].iov_base = const_cast<unsigned char*>(s.data());
	d[1].iov_len = s.size();
	msghdr m;
	m.msg_name = NULL;
	m.msg_namelen = 0;
	m.msg_iov = const_cast<iovec*>(d.data());
	m.msg_iovlen = d.size();
	m.msg_control = NULL;
	m.msg_controllen = 0;
	m.msg_flags = 0;
	int r = sendmsg(m_s, &m, MSG_NOSIGNAL);
#endif
	if (r == SOCKET_ERROR)
	{
		if (WSAGetLastError() != WSAECONNRESET)
			std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl;
	}
	else if (r != h.size() + s.size())
	{
#ifndef WIN32
		if (r < h.size())
		{
			m_write_b.resize(h.size() + s.size());
			memcpy(m_write_b.data_edit(), h.data(), h.size());
			s.read(m_write_b.data_edit() + h.size());
		}
		else
		{
			m_write_b = s;
			r -= h.size();
		}
#endif
		m_r = m_write_b;
		m_r += r;
	}
	if (m_r.empty())
		m_write_b.clear();
}