Commit 56988d7a authored by captainwong's avatar captainwong

JTL

parent f9734b8f
#pragma once
#include <assert.h>
#include "list_node.h"
namespace JTL // Jack's template library
{
template <typename T>
class List
{
private:
int _size;
ListNodePosi(T) header;
ListNodePosi(T) trailer;
protected:
void init();
int clear();
void copy_nodes(ListNodePosi(T), int);
void merge(ListNodePosi(T)&, int, List<T>&, ListNodePosi(T), int);
void merge_sort(ListNodePosi(T)&, int);
void selection_sort(ListNodePosi(T), int);
void insertion_sort(ListNodePosi(T), int);
public:
// Constructor
List() { init(); }
List(List<T> const& L);
List(List<T> const& L, Rank r, int n);
List(ListNodePosi(T) p, int n);
// Destructor
~List();
// Read only
Rank size() const { return _size; }
bool empty() const { return _size <= 0; }
ListNodePosi(T) first() const { return header->succ; }
ListNodePosi(T) last() const { return trailer->pred; }
bool valid(ListNodePosi(T) p) const { return p && p != header && p != trailer; }
T& operator[] (Rank r) const;
int disordered() const;
ListNodePosi(T) find(T const& e) const { return find(e, _size, trailer); }
ListNodePosi(T) find(T const& e, int n, ListNodePosi(T) p) const;
ListNodePosi(T) search(T const& e) const { return search(e, _size, trailer); }
ListNodePosi(T) search(T const& e, int n, ListNodePosi(T) p) const;
ListNodePosi(T) select_max() { return selectMax(header->succ, _size); }
ListNodePosi(T) select_max(ListNodePosi(T) p, int n);
// Writable
ListNodePosi(T) insert_as_first(T const& e);
ListNodePosi(T) insert_as_last(T const& e);
ListNodePosi(T) insert_after(ListNodePosi(T) p, T const& e);
ListNodePosi(T) insert_before(ListNodePosi(T) p, T const& e);
T remove(ListNodePosi(T) p);
void merge(List<T>& L) { merge(first(), _size, L, L.first(), L._size); }
void sort(ListNodePosi(T) p, int n);
void sort() { sort(first(), _size); }
int deduplicate(); // unsorted
int uniquify(); // sorted
};
};
#include "list_implementation.h"
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
T& List<T>::operator[] (Rank r) const
{
assert(0 <= r && r < _size);
ListNodePosi(T) p = first();
while (r--) {
p = p->succ;
}
return p->data;
}
};
\ No newline at end of file
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
int List<T>::clear()
{
int old_size = _size;
while (0 < _size) {
remove(header->succ);
}
return old_size;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
List<T>::List(List<T> const& L)
{
copy_nodes(L.first(), L._size);
}
template <typename T>
List<T>::List(List<T> const& L, Rank r, int n)
{
copy_nodes(L[r], n);
}
template <typename T>
List<T>::List(ListNodePosi(T) p, int n)
{
copy_nodes(p, n);
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::copy_nodes(ListNodePosi(T) p, int n)
{
init();
while (n--) {
insert_as_last(p->data);
p = p->succ;
}
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
int List<T>::deduplicate()
{
if (_size < 2)
return 0;
int old_size = _size;
ListNodePosi(T) p = header;
Rank r = 0;
while ((p = p->succ) != trailer) {
find(p->data, r, p) ? remove(p) : r++;
}
return old_size - _size;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
List<T>::~List()
{
clear();
delete header;
delete trailer;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
int List<T>::disordered() const
{
if (0 == _size) {
return 0;
}
int sum = 0;
ListNodePosi(T) p = first();
for (int i = 0; i < _size - 1; p = p->succ, i++) {
if (p->data > p->succ->data) {
sum++;
}
}
return sum;
}
};
\ No newline at end of file
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
ListNodePosi(T) List<T>::find(T const& e, int n, ListNodePosi(T) p) const
{
assert(valid(p));
while (n--) {
if ((p = p->pred)->data == e) {
return p;
}
}
return NULL;
}
};
#pragma once
#include "list_node.h"
#include "list_bracket.h"
#include "list_clear.h"
#include "list_init.h"
#include "list_copy_nodes.h"
#include "list_copy_constructor.h"
#include "list_destructor.h"
#include "list_insert.h"
#include "list_disordered.h"
#include "list_find.h"
#include "list_search.h"
#include "list_remove.h"
//#include "list_traverse.h"
#include "list_sort.h"
#include "list_insertion_sort.h"
#include "list_select_max.h"
#include "list_selection_sort.h"
#include "list_merge.h"
#include "list_merge_sort.h"
#include "list_deduplicate.h"
#include "list_uniquify.h"
//#include "list_reverse1.h"
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::init()
{
header = new ListNode<T>;
trailer = new ListNode<T>;
header->pred = NULL;
header->succ = trailer;
trailer->pred = header;
trailer->succ = NULL;
_size = 0;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
ListNodePosi(T) List<T>::insert_as_first(T const& e)
{
_size++;
return header->insert_as_succ(e);
}
template <typename T>
ListNodePosi(T) List<T>::insert_as_last(T const& e)
{
_size++;
return trailer->insert_as_pred(e);
}
template <typename T>
ListNodePosi(T) List<T>::insert_after(ListNodePosi(T) p, T const& e)
{
_size++;
return p->insert_as_succ(e);
}
template <typename T>
ListNodePosi(T) List<T>::insert_before(ListNodePosi(T) p, T const& e)
{
_size++;
return p->insert_as_pred(e);
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::insertion_sort(ListNodePosi(T) p, int n)
{
for (int sorted = 0; sorted < n; sorted++) {
insert_after(search(p->data, sorted, p), p->data);
p = p->succ;
remove(p->pred);
}
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::merge(ListNodePosi(T)& p, int n, List<T>& L, ListNodePosi(T) q, int m)
{
ListNodePosi(T) pp = p->pred;
while (0 < m) {
if ((0 < n) && p->data <= q->data) {
if (q == (p = p->succ)) {
break;
}
n--;
} else {
insert_before(p, L.remove((q = q->succ)->pred));
m--;
}
}
p = pp->succ;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::merge_sort(ListNodePosi(T)& p, int n)
{
if (n < 2)
return;
int m = n >> 1;
ListNodePosi(T) q = p;
for (int i = 0; i < m; i++) {
q = q->succ;
}
merge_sort(p, m);
merge_sort(q, n - m);
merge(p, m, *this, q, n - m);
}
};
#pragma once
namespace JTL // Jack's template library
{
typedef int Rank;
#define ListNodePosi(T) ListNode<T>*
template <typename T>
struct ListNode
{
T data;
ListNodePosi(T) pred;
ListNodePosi(T) succ;
ListNode() : data(0), pred(NULL), succ(NULL) {}
ListNode(T e, ListNodePosi(T) p = NULL, ListNodePosi(T) s = NULL)
: data(e), pred(p), succ(s)
{}
ListNodePosi(T) insert_as_pred(T const& e);
ListNodePosi(T) insert_as_succ(T const& e);
};
};
#include "list_node_implementaion.h"
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
ListNodePosi(T) ListNode<T>::insert_as_pred(T const& e)
{
ListNodePosi(T) pos = new ListNode(e, pred, this);
pred->succ = pos;
pred = pos;
return pos;
}
template <typename T>
ListNodePosi(T) ListNode<T>::insert_as_succ(T const& e)
{
ListNodePosi(T) pos = new ListNode<T>(e, this, succ);
succ->pred = pos;
succ = pos;
return pos;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
T List<T>::remove(ListNodePosi(T) p)
{
assert(valid(p));
T data = p->data;
p->pred->succ = p->succ;
p->succ->pred = p->pred;
delete p;
_size--;
return data;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
ListNodePosi(T) List<T>::search(T const& e, int n, ListNodePosi(T) p) const
{
if (_size == 0)
return NULL;
//assert(valid(p));
assert(0 <= n && n <= _size);
while (n-- && p != header->succ) {
if ((p = p->pred)->data <= e) {
break;
}
}
return p;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
ListNodePosi(T) List<T>::select_max(ListNodePosi(T) p, int n)
{
ListNodePosi(T) max_p = p;
for (ListNodePosi(T) cur = p; 1 < n; n--) {
if ((cur = cur->succ)->data >= max_p->data) {
max_p = cur;
}
}
return max_p;
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::selection_sort(ListNodePosi(T) p, int n)
{
ListNodePosi(T) head = p->pred;
ListNodePosi(T) tail = p;
for (int i = 0; i < n; i++) {
tail = tail->succ;
}
while (1 < n) {
ListNodePosi(T) max_p = select_max(head->succ, n);
insert_before(tail, remove(max_p));
tail = tail->pred;
n--;
}
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
void List<T>::sort(ListNodePosi(T) p, int n)
{
merge_sort(p, n);
}
};
#pragma once
namespace JTL // Jack's template library
{
template <typename T>
int List<T>::uniquify()
{
if (_size < 2)
return 0;
int old_size = _size;
ListNodePosi(T) p = first();
ListNodePosi(T) q;
while ((q = p->succ) != trailer) {
if (q->data != p->data) {
p = q;
} else {
remove(q);
}
}
return old_size - _size;
}
};
#pragma once
class Fibnacci
{
private:
int f, g;
public:
Fibnacci(int n)
{
f = 1;
g = 0;
while (g < n) {
next();
}
}
int get()
{
return g;
}
int next()
{
g += f;
f = g - f;
return g;
}
int prev()
{
f = g - f;
g -= f;
return g;
}
};
\ No newline at end of file
#pragma once
namespace JTL // Jack's template library
{
/*
size() 报告向量当前的规模
get(r) 获取秩为r的元素
put(r, e) 用e替换秩为r的元素
insert(r, e) e作为秩为r元素插入,原后继元素依次后移
remove(r) 删除秩为r的元素,返回该元素中原存放的对象
disordered() 判断所有元素是否已按非降序排列
sort() 调整各元素的位置,使之按非降序排列
find(e) 查找目标元素e
search(e) 查找目标元素e,返回不大于e且秩最大的元素 (有序向量)
deduplicate 剔除重复元素
uniquify() 剔除重复元素 (有序向量)
traverse() 遍历向量并统一处理所有元素,处理方法由函数对象指定
*/
typedef int Rank;
static const int DEFAULT_CAPACITY = 3;
//template <typename T>
//void swap(T& a, T& b)
//{
// T t = a;
// a = b;
// b = t;
//}
template <typename T>
class Vector
{
protected:
Rank _size;
int _capacity;
T* _elem;
public:
// Constructors
Vector(int c = DEFAULT_CAPACITY, int s = 0, T v = 0)
{
_elem = new T[_capacity = c];
for (_size = 0; _size < s; _elem[_size++] = v) {}
}
Vector(T const* A, Rank n)
{
copy_from(A, 0, n);
}
Vector(T const* A, Rank lo, Rank hi)
{
copy_from(A, lo, hi);
}
Vector(Vector<T> const& V)
{
copy_from(V._elem, 0, V._size);
}
Vector(Vector<T> const& V, Rank lo, Rank hi)
{
copy_from(V._elem, lo, hi);
}
// Destructor
~Vector()
{
delete[] _elem;
}
// Read only
Rank size() const { return _size; }
bool empty() const { return !_size; }
int disordered() const;
Rank find(T const& e, Rank lo, Rank hi) const;
Rank find(T const& e) const { return find(e, 0, _size); }
Rank search(T const& e) const { return (0 >= _size) ? -1 : search(e, 0, _size); }
Rank search(T const& e, Rank lo, Rank hi) const;
T& operator[] (Rank r) const;
Vector<T>& operator = (Vector<T> const& V);
T remove(Rank r);
int remove(Rank lo, Rank hi);
Rank insert(Rank r, T const& e);
Rank insert(T const& e) { return insert(_size, e); }
void sort(Rank lo, Rank hi);
void sort() { sort(0, _size); }
void unsort(Rank lo, Rank hi);
void unsort() { unsort(0, _size); }
int deduplicate(); // unsorted
int uniquify(); // sorted
protected:
void copy_from(T const* A, Rank lo, Rank hi);
void expand();
void shrink();
bool bubble(Rank lo, Rank hi);
void bubble_sort(Rank lo, Rank hi);
Rank bubble_fast(Rank lo, Rank hi);
void bubble_sort_fast(Rank lo, Rank hi);
void merge(Rank lo, Rank mi, Rank hi);
void merge_sort(Rank lo, Rank hi);
// Common functions
static Rank binary_search(T* A, T const& e, Rank lo, Rank hi);
static Rank fibnacci_search(T* A, T const& e, Rank lo, Rank hi);
static Rank interpolation_search(T* A, T const& e, Rank lo, Rank hi);
};
};
#include "vector_implementation.h"
#include <assert.h>
#include <stdlib.h>
#include "fibnacci.h"
namespace JTL // Jack's template library
{
template <typename T>
void Vector<T>::copy_from(T const* A, Rank lo, Rank hi)
{
_elem = new T[_capacity = 2 * (hi - lo)];
_size = 0;
while (lo < hi) {
_elem[_size++] = A[lo++];
}
}
template <typename T>
void Vector<T>::expand()
{
if (_size < _capacity) {
return;
}
if (_capacity < DEFAULT_CAPACITY) {
_capacity = DEFAULT_CAPACITY;
}
T* old_elem = _elem;
_elem = new T[_capacity <<= 1];
for (int i = 0; i < _size; i++) {
_elem[i] = old_elem[i];
}
delete[] old_elem;
}
template <typename T>
int Vector<T>::disordered() const
{
int n = 0;
for (int i = 1; i < _size; i++) {
if (_elem[i - 1] > _elem[i]) {
n++;
}
}
return n;
}
template <typename T>
Rank Vector<T>::find(T const& e, Rank lo, Rank hi) const
{
assert(0 <= lo);
assert(lo < hi);
assert(hi <= _size);
while ((lo < hi--) && (e != _elem[hi])) {}
return hi;
}
template <typename T>
Rank Vector<T>::search(T const& e, Rank lo, Rank hi) const
{
assert(0 <= lo);
assert(lo < hi);
assert(hi <= _size);
//return (rand() % 2) ?
// binary_search(_elem, e, lo, hi) : fibnacci_search(_elem, e, lo, hi);
return fibnacci_search(_elem, e, lo, hi);
}
template <typename T>
Rank Vector<T>::binary_search(T* A, T const& e, Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo <= hi);
//assert(hi <= _size);
#define USE_VERSION_3
// version 1
#ifdef USE_VERSION_1
while (lo < hi) { // 每步迭代可能要做两次比较判断,有三个分支
Rank mi = (lo + hi) >> 1;
if (e < A[mi]) {
hi = mi;
} else if (A[i] < e) {
lo = mi + 1;
} else {
return mi;
}
}
return -1;
// 有多个命中元素时,不能保证返回秩最大者;
// 查找失败时,简单地返回-1,而不能只是失败的位置
#endif
// version 2
#ifdef USE_VERSION_2
while (1 < hi - lo) { // 每步迭代仅需一次比较
Rank mi = (lo + hi) >> 1;
(e < A[mi]) ? hi = mi : lo = mi;
}// 出口时hi = lo + 1,查找区间仅含一个元素A[lo]
return (e == A[lo]) ? lo : -1; // 查找成功时返回对应的秩,否则统一返回-1
// 有多个命中元素时,不能保证返回秩最大者;
// 查找失败时,简单地返回-1,而不能只是失败的位置
#endif
// version 3
#ifdef USE_VERSION_3
while (lo < hi) { // 每步迭代仅需一次比较
Rank mi = (lo + hi) >> 1;
(e < A[mi]) ? hi = mi : lo = mi + 1;
}// 成功查找不能提前终止
return --lo;//循环结束时,lo为大于e的元素的最小秩,故lo-1即不大于e的元素的最大秩
// 有多个命中元素时,总能保证返回秩最大者
// 查找失败时,能够返回失败的位置
#endif
}
template <typename T>
Rank Vector<T>::fibnacci_search(T* A, T const& e, Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo <= hi);
//assert(hi <= A->_size);
#define USE_VERSION_2
#ifdef USE_VERSION_1
Fibnacci fib(hi - lo);
while (lo < hi) {
while (hi - lo < fib.get()) {
fib.prev();
}
Rank mi = lo + fib.get() - 1;
if (e < A[mi]) {
hi = mi;
} else if (A[mi] < e) {
lo = mi + 1;
} else {
return mi;
}
}
return -1;
// 有多个元素命中时,不能保证返回秩最大者
// 查找失败时,简单地返回-1,而不能只是失败的位置
#endif
#ifdef USE_VERSION_2
Fibnacci fib(hi - lo);
while (lo < hi) {
while (hi - lo < fib.get()) { fib.prev(); }
Rank mi = lo + fib.get() - 1;
(e < A[mi]) ? hi = mi : lo = mi + 1;
}// 成功查找不能提前终止
return --lo;//循环结束时,lo为大于e的元素的最小秩,故lo-1即不大于e的元素的最大秩
// 有多个命中元素时,总能保证返回秩最大者
// 查找失败时,能够返回失败的位置
#endif
}
template <typename T>
Rank Vector<T>::interpolation_search(T* A, T const& e, Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo <= hi);
assert(hi <= A->_size);
while (A[lo] <= e && e <= A[hi]) {
Rank mi = lo + (hi - lo) * (e - A[lo]) / (A[hi] - A[lo]);
if (A[mi] < e) {
lo = mi + 1;
} else if (e < A[mi]) {
hi = mi - 1;
} else {
return mi;
}
}
if (A[lo] == e) {
return lo;
} else {
return -1;
}
}
template <typename T>
void Vector<T>::shrink()
{
if (_capacity < DEFAULT_CAPACITY << 1) { return; }
if (_size << 2 > _capacity) { return; }
T* old_elem = _elem;
_elem = new T[_capacity >= 1];
for (int i = 0; i < _size; i++) {
_elem[i] = old_elem[i];
}
delete[] old_elem;
}
template <typename T>
bool Vector<T>::bubble(Rank lo, Rank hi)
{
bool sorted = true;
while (++lo < hi) {
if (_elem[lo - 1] > _elem[lo]) {
sorted = false;
swap(_elem[lo - 1], _elem[lo]);
}
}
return sorted;
}
template <typename T>
void Vector<T>::bubble_sort(Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo < hi);
assert(hi <= _size);
while (!bubble(lo, hi--)) {}
}
template <typename T>
Rank Vector<T>::bubble_fast(Rank lo, Rank hi)
{
Rank last = lo;
while (++lo < hi) {
if (_elem[lo - 1] > _elem[lo]) {
last = lo;
swap(_elem[lo - 1], _elem[lo]);
}
}
return last;
}
template <typename T>
void Vector<T>::bubble_sort_fast(Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo < hi);
assert(hi <= _size);
while (lo < (hi = bubble_fast(lo, hi))) {}
}
template <typename T>
void Vector<T>::merge(Rank lo, Rank mi, Rank hi)
{
T* A = _elem + lo;
int lb = mi - lo;
T* B = new T[lb]; // [lo, mi)
for (int i = 0; i < lb; i++) {
B[i] = A[i];
}
T* C = _elem + mi; // [mi, hi)
int lc = hi - mi;
for (int i = 0, j = 0, k = 0; (j < lb) || (k < lc);) {
if ((j < lb) && (!(k < lc) || B[j] <= C[k])) {
A[i++] = B[j++];
}
if ((k < lc) && (!(j < lb) || C[k] < B[j])) {
A[i++] = C[k++];
}
}
delete[] B;
}
template <typename T>
void Vector<T>::merge_sort(Rank lo, Rank hi)
{
assert(0 <= lo);
assert(lo < hi);
assert(hi <= _size);
if (hi - lo < 2)
return;
Rank mi = (hi + lo) >> 1;
merge_sort(lo, mi);
merge_sort(mi, hi);
merge(lo, mi, hi);
}
template <typename T>
T& Vector<T>::operator[] (Rank r) const
{
assert(r >= 0 && r < _size);
return _elem[r];
}
template <typename T>
Vector<T>& Vector<T>::operator= (Vector<T> const& V)
{
if (_elem) {
delete[] _elem;
}
copy_from(V._elem, 0, V._size);
return *this;
}
template <typename T>
int Vector<T>::remove(Rank lo, Rank hi)
{
assert(lo >= 0 && lo <= hi && hi <= _size);
if (lo == hi) {
return 0;
}
while (hi < _size) {
_elem[lo++] = _elem[hi++];
}
_size = lo;
shrink();
return hi - lo;
}
template <typename T>
T Vector<T>::remove(Rank r)
{
assert(r >= 0 && r < _size);
T e = _elem[r];
remove(r, r + 1);
return e;
}
template <typename T>
Rank Vector<T>::insert(Rank r, T const& e)
{
assert(r >= 0 && r <= _size);
expand();
for (int i = _size; i > r; i--) {
_elem[i] = _elem[i - 1];
}
_elem[r] = e;
_size++;
return r;
}
template <typename T>
void Vector<T>::sort(Rank lo, Rank hi)
{
/*switch (rand() % 2) {
case 0: bubble_sort_fast(lo, hi); break;
case 1: merge_sort(lo, hi); break;
}*/
merge_sort(lo, hi);
}
template <typename T>
void Vector<T>::unsort(Rank lo, Rank hi)
{
T* V = _elem + lo;
for (Rank i = hi - lo; i > 0; i--) {
swap(V[i] - 1, V[rand() % i]);
}
}
template <typename T>
int Vector<T>::deduplicate()
{
int old_size = _size;
int i = 1;
while (i < _size) {
(find(_elem[i], 0, i) < 0) ? i++ : remove(i);
}
return old_size - _size;
}
template <typename T>
int Vector<T>::uniquify()
{
Rank i = 0, j = 0;
while (++j < _size) {
if (_elem[i] != _elem[j]) {
_elem[++i] = _elem[j];
}
}
_size = ++i;
shrink();
return j - i;
}
};
#pragma once
inline wchar_t* FormatWSAError(int errornumber)
{
switch (errornumber) {
case WSANOTINITIALISED:
return L"A successful WSAStartup call must occur before using this function. ";
break;
case WSAENETDOWN:
return L"The network subsystem has failed. ";
break;
case WSAEACCES:
return L"The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt with the SO_BROADCAST parameter to allow the use of the broadcast address. ";
break;
case WSAEINVAL:
return L"An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled. ";
break;
case WSAEINTR:
return L"A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall. ";
break;
case WSAEINPROGRESS:
return L"A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. ";
break;
case WSAEFAULT:
return L"The buf or to parameters are not part of the user address space, or the tolen parameter is too small. ";
break;
case WSAENETRESET:
return L"The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. ";
break;
case WSAENOBUFS:
return L"No buffer space is available. ";
break;
case WSAENOTCONN:
return L"The socket is not connected (connection-oriented sockets only. ";
break;
case WSAENOTSOCK:
return L"The descriptor is not a socket. ";
break;
case WSAEOPNOTSUPP:
return L"MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations. ";
break;
case WSAESHUTDOWN:
return L"The socket has been shut down; it is not possible to sendto on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH. ";
break;
case WSAEWOULDBLOCK:
return L"The socket is marked as nonblocking and the requested operation would block. ";
break;
case WSAEMSGSIZE:
return L"The socket is message oriented, and the message is larger than the maximum supported by the underlying transport. ";
break;
case WSAEHOSTUNREACH:
return L"The remote host cannot be reached from this host at this time. ";
break;
case WSAECONNABORTED:
return L"The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable. ";
break;
case WSAECONNRESET:
return L"The virtual circuit was reset by the remote side executing a hard or abortive close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a \"Port Unreachable\" ICMP packet. The application should close the socket as it is no longer usable. ";
break;
case WSAEADDRNOTAVAIL:
return L"The remote address is not a valid address, for example, ADDR_ANY. ";
break;
case WSAEAFNOSUPPORT:
return L"Addresses in the specified family cannot be used with this socket. ";
break;
case WSAEDESTADDRREQ:
return L"A destination address is required. ";
break;
case WSAENETUNREACH:
return L"The network cannot be reached from this host at this time. ";
break;
case WSAETIMEDOUT:
return L"The connection has been dropped, because of a network failure or because the system on the other end went down without notice. ";
break;
default:
return L"Unknown socket error.";
break;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment