added MOO_EBADHND

This commit is contained in:
hyunghwan.chung 2017-10-30 01:11:18 +00:00
parent 2c85319cb0
commit d042f0f494
11 changed files with 185 additions and 52 deletions

View File

@ -362,6 +362,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@
@ -595,7 +596,7 @@ distdir: $(DISTFILES)
! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r "$(distdir)" || chmod -R a+r "$(distdir)"
dist-gzip: distdir dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__post_remove_distdir) $(am__post_remove_distdir)
dist-bzip2: distdir dist-bzip2: distdir
@ -621,7 +622,7 @@ dist-shar: distdir
@echo WARNING: "Support for shar distribution archives is" \ @echo WARNING: "Support for shar distribution archives is" \
"deprecated." >&2 "deprecated." >&2
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__post_remove_distdir) $(am__post_remove_distdir)
dist-zip: distdir dist-zip: distdir
@ -639,7 +640,7 @@ dist dist-all:
distcheck: dist distcheck: dist
case '$(DIST_ARCHIVES)' in \ case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \ *.tar.gz*) \
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \ *.tar.bz2*) \
bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.lz*) \ *.tar.lz*) \
@ -649,7 +650,7 @@ distcheck: dist
*.tar.Z*) \ *.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \ *.shar.gz*) \
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
*.zip*) \ *.zip*) \
unzip $(distdir).zip ;;\ unzip $(distdir).zip ;;\
esac esac

14
moo/configure vendored
View File

@ -803,6 +803,7 @@ infodir
docdir docdir
oldincludedir oldincludedir
includedir includedir
runstatedir
localstatedir localstatedir
sharedstatedir sharedstatedir
sysconfdir sysconfdir
@ -900,6 +901,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc' sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com' sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var' localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include' includedir='${prefix}/include'
oldincludedir='/usr/include' oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1152,6 +1154,15 @@ do
| -silent | --silent | --silen | --sile | --sil) | -silent | --silent | --silen | --sile | --sil)
silent=yes ;; silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;; ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1289,7 +1300,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \ datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir libdir localedir mandir runstatedir
do do
eval ac_val=\$$ac_var eval ac_val=\$$ac_var
# Remove trailing slashes. # Remove trailing slashes.
@ -1442,6 +1453,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var] --localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib] --libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include] --includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include] --oldincludedir=DIR C header files for non-gcc [/usr/include]

View File

@ -52,9 +52,11 @@ class Semaphore(Object)
{ {
var waiting_head := nil, var waiting_head := nil,
waiting_tail := nil, waiting_tail := nil,
count := 0, count := 0.
heapIndex := -1,
fireTimeSec := 0, var(#get,#set) heapIndex := -1.
var fireTimeSec := 0,
fireTimeNsec := 0, fireTimeNsec := 0,
ioIndex := -1, ioIndex := -1,
ioHandle := nil, ioHandle := nil,
@ -81,16 +83,6 @@ class Semaphore(Object)
## ================================================================== ## ==================================================================
method heapIndex
{
^heapIndex
}
method heapIndex: anIndex
{
heapIndex := anIndex
}
method fireTime method fireTime
{ {
^fireTimeSec ^fireTimeSec
@ -221,6 +213,13 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
method(#primitive) _removeSemaphore: sem. method(#primitive) _removeSemaphore: sem.
method(#primitive) _wait. method(#primitive) _wait.
method addSemaphore: sem
{
| x |
x := self _addSemaphore: sem.
if (x isError) { thisProcess primError dump. Exception signal: ('Cannot add a semaphore - ' & thisProcess primError) }.
^x
}
method wait method wait
{ {
| r | | r |

View File

@ -3,8 +3,9 @@ class Socket(Object) from 'sck'
var handle := -1. var handle := -1.
method(#primitive) _open(domain, type, proto). method(#primitive) _open(domain, type, proto).
method(#primitive) _connect(a,b,c).
method(#primitive) _close. method(#primitive) _close.
method(#primitive) _connect(a,b,c).
} }
(* TODO: generate these domain and type from the C header *) (* TODO: generate these domain and type from the C header *)
@ -22,27 +23,113 @@ pooldic Socket.Type
extend Socket extend Socket
{ {
method(#class) domain: domain type: type method(#class) new { self messageProhibited: #new }
method(#class) new: size { self messageProhibited: #new: }
method(#class) _domain: domain _type: type
{ {
^super new _open(domain, type, 0). ^super new _open(domain, type, 0).
} }
method beginConnect method(#class) domain: domain type: type
{ {
(* | s |
| s1 s1 | s := super new _open(domain, type, 0).
s1 = Semaphore new. if (s isError) { Exception signal: 'Cannot open socket' }.
s2 = Semaphore new. ^s.
}
s1 signalHandler: [xxxxx]. method close
s2 signalHandler: [xxxxxx]. {
if (self.handle >= 0)
{
## this primitive method may return failure.
## but ignore it in this normal method.
self _close.
self.handle := -1.
}
}
fcntl (nonblock); method asyncConnect: connectBlock
{
| s1 s2 sg |
s1 := Semaphore new.
s2 := Semaphore new.
s1 signalAction: [:sem | Processor unsignal: s1. connectBlock value: true].
s2 signalAction: [:sem | Processor unsignal: s2. connectBlock value: false].
Processor signal: s1 onOutput: self.handle. Processor signal: s1 onOutput: self.handle.
Processor signal: s2 after: timeout. Processor signal: s2 after: 10.
connect (); sg := SemaphoreGroup new.
sg addSemaphore: s1.
sg addSemaphore: s2.
sg addSemaphore: s1.
sg addSemaphore: 10.
sg addSemaphore: s1.
if (self _connect(1, 2, 3) isError)
{
Exception signal: 'Cannot connect to 1,2,3'.
}.
sg wait.
}
method asyncRead: readBlock
{
| s1 s2 |
s1 := Semaphore new.
s2 := Semaphore new.
s1 signalAction: [:sem | readBlock value: true].
s2 signalAction: [:sem | readBlock value: false].
Processor signal: s1 onInput: self.handle.
Processor signal: s2 after: 10.
}
(*
method asyncWrite:
{
| s1 s2 |
s1 := Semaphore new.
s2 := Semaphore new.
s1 signalAction: [:sem | writeBlock value: true].
s2 signalAction: [:sem | writeBlock value: false].
Processor signal: s1 onOutput: self.handle.
Processor signal: s2 after: 10.
}
*) *)
}
(****
class MyObject(Object)
{
method(#class) main
{
| s |
[
s := Socket domain: Socket.Domain.INET type: Socket.Type.STREAM.
s dump.
s asyncConnect: [:result |
##s endConnect: result.
##s beginRead: xxx.
'CONNECTED NOW.............' dump.
].
s close dump.
] on: Exception do: [:ex | ('Exception - ' & ex messageText) dump ].
'----- END OF MAIN ------' dump.
} }
} }
*****)

View File

@ -27,6 +27,7 @@ class MyObject(Object)
'interrupted' 'interrupted'
'pipe error' 'pipe error'
'resource temporarily unavailable' 'resource temporarily unavailable'
'bad system handle'
'data too large' 'data too large'
'message receiver error' 'message receiver error'

View File

@ -132,12 +132,27 @@ class MyObject(Object)
s1 := TcpSocket new. s1 := TcpSocket new.
s1 onEvent: #connected do: [ s1 onEvent: #connected do: [
s1 write: C'GET / HTTP/1.0\n\r'. s1 waitToRead.
##s1 beginWrite: C'GET / HTTP/1.0\n\r'.
] ]
s1 onEvent: #written do: [ s1 onEvent: #written do: [
] ].
s1 on: #read do: s1 onEvent: #readyToRead do: [
s1 connectTo: '1.2.3.4:45'.
].
s1 beginConnect: '1.2.3.4:45' onConnected: [ :result | xxxx].
####
s1 beginConnect: destination onConnected:
s1 endConnect --> return what?
s1 endReceive
s1 beginReceive: buffer callback: [xxxx].
s1 beginSend: data onEnd: [do this].
s1 endSend
s1 beginAccept: [callback]
s1 endAccept -> returns the actual socket
*) *)

View File

@ -398,6 +398,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@

View File

@ -48,26 +48,28 @@ static moo_ooch_t errstr_14[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t'
static moo_ooch_t errstr_15[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'}; static moo_ooch_t errstr_15[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'};
static moo_ooch_t errstr_16[] = {'p','i','p','e',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_16[] = {'p','i','p','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_17[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'}; static moo_ooch_t errstr_17[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_18[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'}; static moo_ooch_t errstr_18[] = {'b','a','d',' ','s','y','s','t','e','m',' ','h','a','n','d','l','e','\0'};
static moo_ooch_t errstr_19[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_19[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'};
static moo_ooch_t errstr_20[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_20[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_21[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'}; static moo_ooch_t errstr_21[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_22[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_22[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'};
static moo_ooch_t errstr_23[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_23[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_24[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_24[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_25[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_25[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_26[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_26[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_27[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_27[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_28[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'}; static moo_ooch_t errstr_28[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_29[] = {'I','/','O',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_29[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'};
static moo_ooch_t errstr_30[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'}; static moo_ooch_t errstr_30[] = {'I','/','O',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_31[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'}; static moo_ooch_t errstr_31[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_32[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'};
static moo_ooch_t* errstr[] = static moo_ooch_t* errstr[] =
{ {
errstr_0, errstr_1, errstr_2, errstr_3, errstr_4, errstr_5, errstr_6, errstr_7, errstr_0, errstr_1, errstr_2, errstr_3, errstr_4, errstr_5, errstr_6, errstr_7,
errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15, errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15,
errstr_16, errstr_17, errstr_18, errstr_19, errstr_20, errstr_21, errstr_22, errstr_23, errstr_16, errstr_17, errstr_18, errstr_19, errstr_20, errstr_21, errstr_22, errstr_23,
errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30, errstr_31 errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30, errstr_31,
errstr_32
}; };
#if defined(MOO_INCLUDE_COMPILER) #if defined(MOO_INCLUDE_COMPILER)
@ -242,6 +244,7 @@ moo_errnum_t moo_syserr_to_errnum (int e)
{ {
case ENOMEM: return MOO_ESYSMEM; case ENOMEM: return MOO_ESYSMEM;
case EINVAL: return MOO_EINVAL; case EINVAL: return MOO_EINVAL;
#if defined(EBUSY) #if defined(EBUSY)
case EBUSY: return MOO_EBUSY; case EBUSY: return MOO_EBUSY;
#endif #endif
@ -272,6 +275,15 @@ moo_errnum_t moo_syserr_to_errnum (int e)
#elif defined(EWOULDBLOCK) #elif defined(EWOULDBLOCK)
case EWOULDBLOCK: return MOO_EAGAIN; case EWOULDBLOCK: return MOO_EAGAIN;
#endif #endif
#if defined(EBADF)
case EBADF: return MOO_EBADHND;
#endif
#if defined(EIO)
case EIO: return MOO_EIOERR;
#endif
default: return MOO_ESYSERR; default: return MOO_ESYSERR;
} }
#endif #endif

View File

@ -64,6 +64,7 @@ enum moo_errnum_t
MOO_EINTR, MOO_EINTR,
MOO_EPIPE, MOO_EPIPE,
MOO_EAGAIN, MOO_EAGAIN,
MOO_EBADHND,
MOO_ENOAVAIL, /**< data not available*/ MOO_ENOAVAIL, /**< data not available*/
MOO_EMSGRCV, /**< mesasge receiver error */ MOO_EMSGRCV, /**< mesasge receiver error */

View File

@ -424,6 +424,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@

View File

@ -98,15 +98,18 @@ static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1) if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
{ {
MOO_STACK_SETRETTOERROR (moo, nargs, moo_syserr_to_errnum(errno)); MOO_STACK_SETRETTOERROR (moo, nargs, moo_syserr_to_errnum(errno));
return MOO_PF_SUCCESS;
} }
else else
{ {
sck->handle = MOO_SMOOI_TO_OOP(-1); sck->handle = MOO_SMOOI_TO_OOP(-1);
MOO_STACK_SETRETTORCV (moo, nargs);
} }
} }
else
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EBADHND);
}
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }