started adding a socket module and the Socket class
This commit is contained in:
@ -23,11 +23,18 @@ if ENABLE_STATIC_MODULE
|
||||
LDFLAGS_COMMON =-L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
LIBADD_COMMON =
|
||||
|
||||
noinst_LTLIBRARIES = libmoo-console.la libmoo-stdio.la
|
||||
noinst_LTLIBRARIES =
|
||||
|
||||
if ENABLE_MOD_FFI
|
||||
noinst_LTLIBRARIES += libmoo-ffi.la
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
noinst_LTLIBRARIES += libmoo-sck.la
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES += libmoo-stdio.la
|
||||
|
||||
if ENABLE_MOD_X11
|
||||
noinst_LTLIBRARIES += libmoo-x11.la
|
||||
endif
|
||||
@ -41,11 +48,20 @@ LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-un
|
||||
LIBADD_COMMON = -lmoo
|
||||
|
||||
pkgmodexecdir = $(libdir)
|
||||
pkgmodexec_LTLIBRARIES = libmoo-console.la libmoo-stdio.la
|
||||
pkgmodexec_LTLIBRARIES =
|
||||
|
||||
pkgmodexec_LTLIBRARIES += libmoo-console.la
|
||||
|
||||
if ENABLE_MOD_FFI
|
||||
pkgmodexec_LTLIBRARIES += libmoo-ffi.la
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
pkgmodexec_LTLIBRARIES += libmoo-sck.la
|
||||
endif
|
||||
|
||||
pkgmodexec_LTLIBRARIES += libmoo-stdio.la
|
||||
|
||||
if ENABLE_MOD_X11
|
||||
pkgmodexec_LTLIBRARIES += libmoo-x11.la
|
||||
endif
|
||||
@ -64,6 +80,13 @@ libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS)
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
libmoo_sck_la_SOURCES = sck.c _sck.h
|
||||
libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_sck_la_LIBADD = $(LIBADD_COMMON)
|
||||
endif
|
||||
|
||||
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
|
||||
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
|
@ -94,9 +94,11 @@ host_triplet = @host@
|
||||
@WIN32_TRUE@am__append_1 = -DMOO_DEFAULT_PFMODPREFIX=\"libmoo-\" -DMOO_DEFAULT_PFMODPOSTFIX=\"-1\"
|
||||
@WIN32_FALSE@am__append_2 = -DMOO_DEFAULT_PFMODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_PFMODPOSTFIX=\"\"
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_3 = libmoo-ffi.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_4 = libmoo-x11.la
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_5 = libmoo-ffi.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_6 = libmoo-x11.la
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_4 = libmoo-sck.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_5 = libmoo-x11.la
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_6 = libmoo-ffi.la
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_7 = libmoo-sck.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_8 = libmoo-x11.la
|
||||
subdir = mod
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_namespace.m4 \
|
||||
@ -156,7 +158,6 @@ libmoo_console_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
|
||||
-o $@
|
||||
@ENABLE_STATIC_MODULE_FALSE@am_libmoo_console_la_rpath = -rpath \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am_libmoo_console_la_rpath =
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_1) \
|
||||
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_1)
|
||||
@ -170,6 +171,18 @@ libmoo_ffi_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_ffi_la_rpath =
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_SCK_TRUE@ $(am__DEPENDENCIES_1)
|
||||
am__libmoo_sck_la_SOURCES_DIST = sck.c _sck.h
|
||||
@ENABLE_MOD_SCK_TRUE@am_libmoo_sck_la_OBJECTS = libmoo_sck_la-sck.lo
|
||||
libmoo_sck_la_OBJECTS = $(am_libmoo_sck_la_OBJECTS)
|
||||
libmoo_sck_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_sck_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_sck_la_rpath = \
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_sck_la_rpath =
|
||||
libmoo_stdio_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libmoo_stdio_la_OBJECTS = libmoo_stdio_la-stdio.lo
|
||||
libmoo_stdio_la_OBJECTS = $(am_libmoo_stdio_la_OBJECTS)
|
||||
@ -227,9 +240,11 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||
am__v_CCLD_1 =
|
||||
SOURCES = $(libmoo_console_la_SOURCES) $(libmoo_ffi_la_SOURCES) \
|
||||
$(libmoo_stdio_la_SOURCES) $(libmoo_x11_la_SOURCES)
|
||||
$(libmoo_sck_la_SOURCES) $(libmoo_stdio_la_SOURCES) \
|
||||
$(libmoo_x11_la_SOURCES)
|
||||
DIST_SOURCES = $(libmoo_console_la_SOURCES) \
|
||||
$(am__libmoo_ffi_la_SOURCES_DIST) $(libmoo_stdio_la_SOURCES) \
|
||||
$(am__libmoo_ffi_la_SOURCES_DIST) \
|
||||
$(am__libmoo_sck_la_SOURCES_DIST) $(libmoo_stdio_la_SOURCES) \
|
||||
$(am__libmoo_x11_la_SOURCES_DIST)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
@ -435,13 +450,14 @@ CPPFLAGS_COMMON = -I$(abs_builddir) -I$(abs_builddir)/../lib \
|
||||
@ENABLE_STATIC_MODULE_TRUE@LDFLAGS_COMMON = -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = -lmoo
|
||||
@ENABLE_STATIC_MODULE_TRUE@LIBADD_COMMON =
|
||||
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = libmoo-console.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ libmoo-stdio.la $(am__append_3) \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_4)
|
||||
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = $(am__append_3) \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_4) libmoo-stdio.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_5)
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir)
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ libmoo-console.la libmoo-stdio.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_5) $(am__append_6)
|
||||
@ENABLE_STATIC_MODULE_FALSE@ libmoo-console.la $(am__append_6) \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_7) libmoo-stdio.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_8)
|
||||
libmoo_console_la_SOURCES = console.c console.h
|
||||
libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_console_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ -450,6 +466,10 @@ libmoo_console_la_LIBADD = $(LIBADD_COMMON) $(TERMINAL_LIBS)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_SOURCES = sck.c _sck.h
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LIBADD = $(LIBADD_COMMON)
|
||||
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
|
||||
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ -544,6 +564,9 @@ libmoo-console.la: $(libmoo_console_la_OBJECTS) $(libmoo_console_la_DEPENDENCIES
|
||||
libmoo-ffi.la: $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_DEPENDENCIES) $(EXTRA_libmoo_ffi_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_ffi_la_LINK) $(am_libmoo_ffi_la_rpath) $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-sck.la: $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_DEPENDENCIES) $(EXTRA_libmoo_sck_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_sck_la_LINK) $(am_libmoo_sck_la_rpath) $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-stdio.la: $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_DEPENDENCIES) $(EXTRA_libmoo_stdio_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_stdio_la_LINK) $(am_libmoo_stdio_la_rpath) $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_LIBADD) $(LIBS)
|
||||
|
||||
@ -558,6 +581,7 @@ distclean-compile:
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_console_la-console.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_ffi_la-ffi.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_sck_la-sck.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11.Plo@am__quote@
|
||||
|
||||
@ -599,6 +623,13 @@ libmoo_ffi_la-ffi.lo: ffi.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_ffi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_ffi_la-ffi.lo `test -f 'ffi.c' || echo '$(srcdir)/'`ffi.c
|
||||
|
||||
libmoo_sck_la-sck.lo: sck.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_sck_la-sck.lo -MD -MP -MF $(DEPDIR)/libmoo_sck_la-sck.Tpo -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_sck_la-sck.Tpo $(DEPDIR)/libmoo_sck_la-sck.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sck.c' object='libmoo_sck_la-sck.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
|
||||
|
||||
libmoo_stdio_la-stdio.lo: stdio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_stdio_la-stdio.lo -MD -MP -MF $(DEPDIR)/libmoo_stdio_la-stdio.Tpo -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_stdio_la-stdio.Tpo $(DEPDIR)/libmoo_stdio_la-stdio.Plo
|
||||
|
52
moo/mod/_sck.h
Normal file
52
moo/mod/_sck.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_SCK_H_
|
||||
#define _MOO_MOD_SCK_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
typedef struct sck_t* oop_sck_t;
|
||||
struct sck_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
|
||||
moo_oop_t handle; /* SmallInteger */
|
||||
/* there are more fields in the actual object */
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_sck (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -113,7 +113,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
|
||||
dc = dcNewCallVM (4096); /* TODO: right size? */
|
||||
if (!dc)
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
moo->vmprim.dl_close (moo, handle);
|
||||
goto softfail;
|
||||
}
|
||||
|
208
moo/mod/sck.c
Normal file
208
moo/mod/sck.c
Normal file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "_sck.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
|
||||
static moo_pfrc_t pf_open_socket (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_t dom, type, proto;
|
||||
int fd = -1;
|
||||
moo_errnum_t errnum;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t))
|
||||
);
|
||||
|
||||
dom = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
type = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
proto = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_SMOOI(dom) && MOO_OOP_IS_SMOOI(type) && MOO_OOP_IS_SMOOI(proto));
|
||||
|
||||
fd = socket (MOO_OOP_TO_SMOOI(dom), MOO_OOP_TO_SMOOI(type), MOO_OOP_TO_SMOOI(proto));
|
||||
if (fd == -1)
|
||||
{
|
||||
errnum = moo_syserr_to_errnum(errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (!MOO_IN_SMOOI_RANGE(fd))
|
||||
{
|
||||
/* the file descriptor is too big to be represented as a small integer */
|
||||
errnum = MOO_ERANGE;
|
||||
goto oops;
|
||||
}
|
||||
|
||||
sck->handle = MOO_SMOOI_TO_OOP(fd);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
oops:
|
||||
if (fd >= 0) close (fd);
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, errnum);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
int fd;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd >= 0)
|
||||
{
|
||||
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
|
||||
{
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, moo_syserr_to_errnum(errno));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
sck->handle = MOO_SMOOI_TO_OOP(-1);
|
||||
}
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
int fd, oldfl, n;
|
||||
moo_errnum_t errnum;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle));
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
|
||||
oldfl = fcntl(fd, F_GETFL, 0);
|
||||
if (oldfl == -1 || fcntl(fd, F_SETFL, oldfl | O_NONBLOCK) == -1) goto oops_syserr;
|
||||
|
||||
{
|
||||
|
||||
struct sockaddr_in sin;
|
||||
memset (&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = inet_addr ("1.234.53.142");
|
||||
sin.sin_port = htons(80);
|
||||
do
|
||||
{
|
||||
n = connect(fd, (struct sockaddr*)&sin, sizeof(sin));
|
||||
}
|
||||
while (n == -1 && errno == EINTR);
|
||||
}
|
||||
|
||||
if (n == -1 && errno != EINPROGRESS)
|
||||
{
|
||||
fcntl (fd, F_SETFL, oldfl);
|
||||
goto oops_syserr;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
oops_syserr:
|
||||
errnum = moo_syserr_to_errnum(errno);
|
||||
|
||||
oops:
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, errnum);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
typedef struct fnctab_t fnctab_t;
|
||||
struct fnctab_t
|
||||
{
|
||||
moo_method_type_t type;
|
||||
moo_ooch_t mthname[15];
|
||||
int variadic;
|
||||
moo_pfimpl_t handler;
|
||||
};
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, { '_','c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } },
|
||||
{ I, { '_','c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 3, 3 } },
|
||||
{ I, { '_','o','p','e','n','\0' }, 0, { pf_open_socket, 3, 3 } },
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
/*if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(sck_t), MOO_NULL) <= -1) return -1;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
|
||||
}
|
||||
|
||||
int moo_mod_sck (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->query = query;
|
||||
mod->unload = unload;
|
||||
mod->ctx = MOO_NULL;
|
||||
return 0;
|
||||
}
|
@ -75,7 +75,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
|
||||
#endif
|
||||
if (!stdio->fp)
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
|
||||
|
||||
if (fwrite (bcs, 1, bcslen, stdio->fp) < bcslen)
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
@ -169,8 +169,8 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
|
||||
puts_string:
|
||||
if (fwrite (x->slot, 1, MOO_OBJ_GET_SIZE(x), stdio->fp) < MOO_OBJ_GET_SIZE(x))
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
|
||||
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
goto softfail;
|
||||
}
|
||||
#endif
|
||||
|
@ -705,34 +705,39 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_ooi_t nargs)
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_set))
|
||||
{
|
||||
moo_oow_t ucslen, bcslen;
|
||||
moo_oow_t bcslen;
|
||||
moo_bch_t* bb;
|
||||
int ascent = 10;
|
||||
XRectangle r;
|
||||
|
||||
ucslen = MOO_OBJ_GET_SIZE(a3);
|
||||
if (moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &ucslen, MOO_NULL, &bcslen) <= -1 ||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_oow_t oocslen;
|
||||
|
||||
oocslen = MOO_OBJ_GET_SIZE(a3);
|
||||
if (moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, MOO_NULL, &bcslen) <= -1 ||
|
||||
!(bb = moo_allocmem (moo, MOO_SIZEOF(moo_bch_t) * bcslen)))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.draw_string> Error in converting a string\n");
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
//#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &ucslen, bb, &bcslen);
|
||||
//#else
|
||||
// moo_copybcstr (&bb->fn[parlen], bcslen + 1, arg->name);
|
||||
//#endif
|
||||
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, bb, &bcslen);
|
||||
#else
|
||||
bb = MOO_OBJ_GET_CHAR_SLOT(a3);
|
||||
bcslen = oocslen;
|
||||
#endif
|
||||
|
||||
XmbTextExtents(MOO_OOP_TO_SMPTR(gc->font_set), bb, bcslen, MOO_NULL, &r);
|
||||
ascent = r.height;
|
||||
|
||||
/* what about Xutf8DrawString? */
|
||||
XmbDrawString (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle),
|
||||
MOO_OOP_TO_SMPTR(gc->font_set), MOO_OOP_TO_SMPTR(gc->gc_handle),
|
||||
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, bb, bcslen);
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_freemem (moo, bb);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user