Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jinohkang-theori committed Nov 12, 2021
0 parents commit 5ae6e2b
Show file tree
Hide file tree
Showing 12 changed files with 2,301 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2021 Jinoh Kang

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# no-ident: workaround MinGW issue ident section duplication
MINGW_EXTRACFLAGS = -fno-ident
MINGW_EXTRALDFLAGS = -Wl,--gc-sections -Wl,--unique=.ident

ifeq ($(USE32),$(if $(USE32),0))
CROSSPREFIX ?= x86_64-w64-mingw32-
O ?= amd64/
LDFLAGS64 ?= -Wl,--high-entropy-va
LDFLAGS_ARCH = $(LDFLAGS64)
else
CROSSPREFIX ?= i686-w64-mingw32-
O ?= x86/
LDFLAGS_ARCH = $(LDFLAGS32)
endif

CC = $(CROSSPREFIX)gcc
WINDRES = $(CROSSPREFIX)windres

CFLAGS = -Wall -Wextra -g -O2 $(MINGW_EXTRACFLAGS) $(EXTRACFLAGS)
LDFLAGS = -municode -mconsole -Wl,--tsaware -Wl,--nxcompat -Wl,--dynamicbase $(MINGW_EXTRALDFLAGS) $(EXTRALDFLAGS) $(LDFLAGS_ARCH)
LIBS = -lkernel32 -ladvapi32 -lws2_32

all: $(O)pipetcp.exe

$(O)pipetcp.exe: $(O)pipetcp.o $(O)rsrc.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)

$(O)pipetcp.o: pipetcp.c list.h ring.h errors.h udm.h
$(CC) $(CFLAGS) -c -o $@ $<

$(O)rsrc.o: pipetcp.rc
$(WINDRES) --output-format=coff -o $@ $<

clean:
@rm -f $(O)pipetcp.exe $(O)pipetcp.o $(O)rsrc.o

.PHONY: all clean
2 changes: 2 additions & 0 deletions amd64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
*.exe
80 changes: 80 additions & 0 deletions errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2021 Jinoh Kang
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PIPETCP_ERRORS_H
#define PIPETCP_ERRORS_H

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winbase.h>

static BOOL is_failure(DWORD err)
{
switch (err) {
case ERROR_SUCCESS:
case ERROR_MORE_DATA:
case ERROR_IO_PENDING:
return FALSE;
default:
return TRUE;
}
}

static BOOL is_error_nonrecoverable(DWORD err)
{
switch (err) {
case ERROR_BROKEN_PIPE:
case ERROR_NO_DATA:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_STATE:
return TRUE;
case ERROR_RETRY:
case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_NOT_ENOUGH_QUOTA:
case ERROR_NO_SYSTEM_RESOURCES:
default:
return FALSE;
}
}

static BOOL is_wsa_error_nonrecoverable(DWORD err)
{
switch (err) {
case WSAEBADF:
case WSAENOTSOCK:
case WSAECONNABORTED:
case WSAECONNRESET:
case WSAESHUTDOWN:
case WSAENOTCONN:
case WSAEISCONN:
case WSAECONNREFUSED:
case WSAEDISCON:
return TRUE;
default:
return is_error_nonrecoverable(err);
}
}

#endif
86 changes: 86 additions & 0 deletions list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2021 Jinoh Kang
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef PIPETCP_LIST_H
#define PIPETCP_LIST_H

struct listhead
{
struct listhead *next;
struct listhead *prev;
};

static void list_init(struct listhead *list)
{
list->next = list;
list->prev = list;
}

static int list_empty(struct listhead *list)
{
return list->next == list && list->prev == list;
}

static void list_insert_internal(struct listhead *item, struct listhead *prev, struct listhead *next)
{
item->prev = prev;
item->next = next;
prev->next = item;
next->prev = item;
}

static void list_append(struct listhead *list, struct listhead *item)
{
list_insert_internal(item, list->prev, list);
}

static void list_remove_internal(struct listhead *next, struct listhead *prev)
{
next->prev = prev;
prev->next = next;
}

static void list_remove(struct listhead *item)
{
list_remove_internal(item->next, item->prev);
list_init(item);
}

static struct listhead *list_first(struct listhead *item)
{
struct listhead *next = item->next;
return next == item ? NULL : next;
}

static struct listhead *list_last(struct listhead *item)
{
struct listhead *next = item->next;
return next == item ? NULL : next;
}

#define foreach_list_safe(list, iter, next) \
for ((iter) = (list)->next; \
(next) = (iter)->next, (iter) != (list); \
(iter) = (next))

#endif
Loading

0 comments on commit 5ae6e2b

Please sign in to comment.