Created
January 12, 2015 16:16
-
-
Save kik/2dde94b9caeb652be95a to your computer and use it in GitHub Desktop.
ATS2でリソース管理。ソケット開いて閉じるだけ。普通のcloseでは失敗する場合のある闇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "share/atspre_define.hats" | |
#include "share/atspre_staload.hats" | |
staload S = "libc/sys/SATS/socket.sats" | |
extern | |
fun socket(af: $S.sa_family_t, st: $S.socktype_t, proto: int) : [fd:int] | |
( | |
option_v ($S.socket_v (fd, $S.init), fd >= 0) | int(fd) | |
) = "mac#socket" | |
implement main0 () = let | |
val (pf | s) = socket($S.AF_INET, $S.SOCK_STREAM, 0) | |
in | |
if s >= 0 then let | |
prval Some_v(pfs) = pf | |
in | |
$S.socket_close_exn(pfs | s) | |
end else let | |
prval None_v() = pf | |
in | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
なんか作者はもっとやる気なくって、ばっつばっつassertにしちゃってますね。。。 < socketとか / https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/EFFECTIVATS/HttpServer/myserver.dats