本文整理汇总了C++中GetOpenFile函数的典型用法代码示例。如果您正苦于以下问题:C++ GetOpenFile函数的具体用法?C++ GetOpenFile怎么用?C++ GetOpenFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetOpenFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: bsock_getpeereid
/*
* call-seq:
* basicsocket.getpeereid => [euid, egid]
*
* Returns the user and group on the peer of the UNIX socket.
* The result is a two element array which contains the effective uid and the effective gid.
*
* Socket.unix_server_loop("/tmp/sock") {|s|
* begin
* euid, egid = s.getpeereid
*
* # Check the connected client is myself or not.
* next if euid != Process.uid
*
* # do something about my resource.
*
* ensure
* s.close
* end
* }
*
*/
static VALUE
bsock_getpeereid(VALUE self)
{
UNRUBBY_SOCKET_HACK;
#if defined(HAVE_GETPEEREID)
rb_io_t *fptr;
uid_t euid;
gid_t egid;
GetOpenFile(self, fptr);
if (getpeereid(fptr->fd, &euid, &egid) == -1)
rb_sys_fail("getpeereid");
return rb_assoc_new(UIDT2NUM(euid), GIDT2NUM(egid));
#elif defined(SO_PEERCRED) /* GNU/Linux */
rb_io_t *fptr;
struct ucred cred;
socklen_t len = sizeof(cred);
GetOpenFile(self, fptr);
if (getsockopt(fptr->fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1)
rb_sys_fail("getsockopt(SO_PEERCRED)");
return rb_assoc_new(UIDT2NUM(cred.uid), GIDT2NUM(cred.gid));
#elif defined(HAVE_GETPEERUCRED) /* Solaris */
rb_io_t *fptr;
ucred_t *uc = NULL;
VALUE ret;
GetOpenFile(self, fptr);
if (getpeerucred(fptr->fd, &uc) == -1)
rb_sys_fail("getpeerucred");
ret = rb_assoc_new(UIDT2NUM(ucred_geteuid(uc)), GIDT2NUM(ucred_getegid(uc)));
ucred_free(uc);
return ret;
#endif
}
开发者ID:richo,项目名称:unrubby,代码行数:54,代码来源:basicsocket.c
示例2: ttymode
static VALUE
ttymode(VALUE io, VALUE (*func)(VALUE), void (*setter)(conmode *, void *), void *arg)
{
rb_io_t *fptr;
int status = -1;
int error = 0;
int fd[FD_PER_IO];
conmode t[FD_PER_IO];
VALUE result = Qnil;
GetOpenFile(io, fptr);
fd[0] = GetReadFD(fptr);
if (fd[0] != -1) {
if (set_ttymode(fd[0], t+0, setter, arg)) {
status = 0;
}
else {
error = errno;
fd[0] = -1;
}
}
fd[1] = GetWriteFD(fptr);
if (fd[1] != -1 && fd[1] != fd[0]) {
if (set_ttymode(fd[1], t+1, setter, arg)) {
status = 0;
}
else {
error = errno;
fd[1] = -1;
}
}
if (status == 0) {
result = rb_protect(func, io, &status);
}
GetOpenFile(io, fptr);
if (fd[0] != -1 && fd[0] == GetReadFD(fptr)) {
if (!setattr(fd[0], t+0)) {
error = errno;
status = -1;
}
}
if (fd[1] != -1 && fd[1] != fd[0] && fd[1] == GetWriteFD(fptr)) {
if (!setattr(fd[1], t+1)) {
error = errno;
status = -1;
}
}
if (status) {
if (status == -1) {
errno = error;
rb_sys_fail(0);
}
rb_jump_tag(status);
}
return result;
}
开发者ID:takuto-h,项目名称:ruby,代码行数:56,代码来源:console.c
示例3: frostbitten_message_write_to_io
VALUE frostbitten_message_write_to_io(VALUE self, VALUE io) {
fb_message *message;
Data_Get_Struct(self, fb_message, message);
frostbitten_header_write_to_io(message->header, io);
uint32_t arrayLength = (uint32_t)RARRAY_LEN(message->words);
uint32_t packetSize = 0;
char** strings = frostbitten_message_generate(message, &packetSize);
packetSize += sizeof(uint32_t); // Header
packetSize += sizeof(uint32_t); // packetSize
packetSize += sizeof(uint32_t); // wordCount
rb_io_t *fptr;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
FILE *fp = rb_io_stdio_file(fptr);
fwrite((const void*)&packetSize,sizeof(uint32_t),1,fp);
fwrite((const void*)&arrayLength,sizeof(uint32_t),1,fp);
for(uint32_t i=0; i < arrayLength; i++) {
char *str = strings[i];
uint32_t len = (uint32_t)strlen(str);
fwrite((const void*)&len, sizeof(uint32_t), 1, fp);
fwrite(str, sizeof(char), strlen(str)+1, fp);
}
fflush(fp);
return self;
}
开发者ID:mrevilme,项目名称:frostbitten,代码行数:30,代码来源:message.c
示例4: ScreenBackgroundImage
void TextWindow::ScreenBackgroundImage(int link, uint32_t v) {
if(SS.bgImage.fromFile) MemFree(SS.bgImage.fromFile);
SS.bgImage.fromFile = NULL;
if(link == 'l') {
FILE *f = NULL;
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
char importFile[MAX_PATH] = "";
if(!GetOpenFile(importFile, PNG_EXT, PNG_PATTERN)) goto err;
f = fopen(importFile, "rb");
if(!f) goto err;
uint8_t header[8];
if (fread(header, 1, 8, f) != 8)
goto err;
if(png_sig_cmp(header, 0, 8)) goto err;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if(!png_ptr) goto err;
info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) goto err;
if(setjmp(png_jmpbuf(png_ptr))) goto err;
png_init_io(png_ptr, f);
png_set_sig_bytes(png_ptr, 8);
png_read_png(png_ptr, info_ptr,
PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_STRIP_ALPHA, NULL);
int w; w = (int)png_get_image_width(png_ptr, info_ptr);
int h; h = (int)png_get_image_height(png_ptr, info_ptr);
uint8_t **rows; rows = png_get_rows(png_ptr, info_ptr);
// Round to next-highest powers of two, since the textures require
// that. And round up to 4, to guarantee 32-bit alignment.
int rw; rw = max(4, RoundUpToPowerOfTwo(w));
int rh; rh = max(4, RoundUpToPowerOfTwo(h));
SS.bgImage.fromFile = (uint8_t *)MemAlloc(rw*rh*3);
{for(int i = 0; i < h; i++) {
memcpy(SS.bgImage.fromFile + ((h - 1) - i)*(rw*3), rows[i], w*3);
}}
SS.bgImage.w = w;
SS.bgImage.h = h;
SS.bgImage.rw = rw;
SS.bgImage.rh = rh;
SS.bgImage.scale = SS.GW.scale;
SS.bgImage.origin = SS.GW.offset.ScaledBy(-1);
err:
if(png_ptr) png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
if(f) fclose(f);
}
SS.later.showTW = true;
}
开发者ID:tmpvar,项目名称:solvespace,代码行数:60,代码来源:style.cpp
示例5: ossl_ssl_setup
static VALUE
ossl_ssl_setup(VALUE self)
{
VALUE io, v_ctx, cb;
SSL_CTX *ctx;
SSL *ssl;
rb_io_t *fptr;
Data_Get_Struct(self, SSL, ssl);
if(!ssl){
v_ctx = ossl_ssl_get_ctx(self);
Data_Get_Struct(v_ctx, SSL_CTX, ctx);
ssl = SSL_new(ctx);
if (!ssl) {
ossl_raise(eSSLError, "SSL_new:");
}
DATA_PTR(self) = ssl;
io = ossl_ssl_get_io(self);
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_io_check_writable(fptr);
SSL_set_fd(ssl, TO_SOCKET(FPTR_TO_FD(fptr)));
SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void*)self);
cb = ossl_sslctx_get_verify_cb(v_ctx);
SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void*)cb);
cb = ossl_sslctx_get_client_cert_cb(v_ctx);
SSL_set_ex_data(ssl, ossl_ssl_ex_client_cert_cb_idx, (void*)cb);
cb = ossl_sslctx_get_tmp_dh_cb(v_ctx);
SSL_set_ex_data(ssl, ossl_ssl_ex_tmp_dh_callback_idx, (void*)cb);
}
return Qtrue;
}
开发者ID:srirammca53,项目名称:update_status,代码行数:35,代码来源:ossl_ssl.c
示例6: io_wait_writable
/*
* call-seq:
* io.wait_writable -> IO
* io.wait_writable(timeout) -> IO or nil
*
* Waits until IO writable is available or times out and returns self or
* nil when EOF is reached.
*/
static VALUE
io_wait_writable(int argc, VALUE *argv, VALUE io)
{
rb_io_t *fptr;
int i;
VALUE timeout;
struct timeval timerec;
struct timeval *tv;
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
if (NIL_P(timeout)) {
tv = NULL;
}
else {
timerec = rb_time_interval(timeout);
tv = &timerec;
}
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_OUT, tv);
if (i < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
if (i & RB_WAITFD_OUT)
return io;
return Qnil;
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:36,代码来源:wait.c
示例7: rb_gsl_open_readfile
FILE* rb_gsl_open_readfile(VALUE io, int *flag)
{
rb_io_t *fptr = NULL;
FILE *fp = NULL;
char *name;
switch (TYPE(io)) {
case T_STRING:
name = RSTRING_PTR(io);
fp = fopen(name, "r");
*flag = 1;
break;
case T_FILE:
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
fp = rb_io_stdio_file(fptr);
*flag = 0;
break;
default:
rb_raise(rb_eTypeError, "argv 1 String or File expected");
break;
}
// if (fp == NULL) rb_raise(rb_eIOError, "Cannot open file %s.", name);
if (fp == NULL) rb_raise(rb_eIOError, "Cannot open file");
return fp;
}
开发者ID:blackwinter,项目名称:rb-gsl,代码行数:25,代码来源:common.c
示例8: io_wait_readable
static VALUE
io_wait_readable(int argc, VALUE *argv, VALUE io)
{
rb_io_t *fptr;
int i;
ioctl_arg n;
VALUE timeout;
struct timeval timerec;
struct timeval *tv;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
if (NIL_P(timeout)) {
tv = NULL;
}
else {
timerec = rb_time_interval(timeout);
tv = &timerec;
}
if (rb_io_read_pending(fptr)) return Qtrue;
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, tv);
if (i < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
return Qnil;
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:31,代码来源:wait.c
示例9: ossl_start_ssl
static VALUE
ossl_start_ssl(VALUE self, int (*func)(), const char *funcname)
{
SSL *ssl;
rb_io_t *fptr;
int ret, ret2;
VALUE cb_state;
rb_ivar_set(self, ID_callback_state, Qnil);
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
for(;;){
if((ret = func(ssl)) > 0) break;
switch((ret2 = ssl_get_error(ssl, ret))){
case SSL_ERROR_WANT_WRITE:
rb_io_wait_writable(FPTR_TO_FD(fptr));
continue;
case SSL_ERROR_WANT_READ:
rb_io_wait_readable(FPTR_TO_FD(fptr));
continue;
case SSL_ERROR_SYSCALL:
if (errno) rb_sys_fail(funcname);
ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
default:
ossl_raise(eSSLError, "%s returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
}
}
cb_state = rb_ivar_get(self, ID_callback_state);
if (!NIL_P(cb_state))
rb_jump_tag(NUM2INT(cb_state));
return self;
}
开发者ID:srirammca53,项目名称:update_status,代码行数:35,代码来源:ossl_ssl.c
示例10: rb_gsl_open_readfile
FILE* rb_gsl_open_readfile(VALUE io, int *flag)
{
#ifdef RUBY_1_9_LATER
rb_io_t *fptr = NULL;
#else
OpenFile *fptr = NULL;
#endif
FILE *fp = NULL;
char *name;
switch (TYPE(io)) {
case T_STRING:
name = RSTRING_PTR(io);
fp = fopen(name, "r");
*flag = 1;
break;
case T_FILE:
GetOpenFile(io, fptr);
name = fptr->path;
rb_io_check_readable(fptr);
#ifdef RUBY_1_9_LATER
fp = rb_io_stdio_file(fptr);
#else
fp = fptr->f;
#endif
*flag = 0;
break;
default:
rb_raise(rb_eTypeError, "argv 1 String or File expected");
break;
}
if (fp == NULL) rb_raise(rb_eIOError, "Cannot open file %s.", name);
return fp;
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:33,代码来源:common.c
示例11: bsock_shutdown
/*
* call-seq:
* basicsocket.shutdown([how]) => 0
*
* Calls shutdown(2) system call.
*
* s.shutdown(Socket::SHUT_RD) disallows further read.
*
* s.shutdown(Socket::SHUT_WR) disallows further write.
*
* s.shutdown(Socket::SHUT_RDWR) disallows further read and write.
*
* _how_ can be symbol or string:
* - :RD, :SHUT_RD, "RD" and "SHUT_RD" are accepted as Socket::SHUT_RD.
* - :WR, :SHUT_WR, "WR" and "SHUT_WR" are accepted as Socket::SHUT_WR.
* - :RDWR, :SHUT_RDWR, "RDWR" and "SHUT_RDWR" are accepted as Socket::SHUT_RDWR.
*
* UNIXSocket.pair {|s1, s2|
* s1.puts "ping"
* s1.shutdown(:WR)
* p s2.read #=> "ping\n"
* s2.puts "pong"
* s2.close
* p s1.read #=> "pong\n"
* }
*
*/
static VALUE
bsock_shutdown(int argc, VALUE *argv, VALUE sock)
{
UNRUBBY_SOCKET_HACK;
VALUE howto;
int how;
rb_io_t *fptr;
if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
rb_raise(rb_eSecurityError, "Insecure: can't shutdown socket");
}
rb_scan_args(argc, argv, "01", &howto);
if (howto == Qnil)
how = SHUT_RDWR;
else {
how = rsock_shutdown_how_arg(howto);
if (how != SHUT_WR && how != SHUT_RD && how != SHUT_RDWR) {
rb_raise(rb_eArgError, "`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR");
}
}
GetOpenFile(sock, fptr);
if (shutdown(fptr->fd, how) == -1)
rb_sys_fail(0);
return INT2FIX(0);
}
开发者ID:richo,项目名称:unrubby,代码行数:53,代码来源:basicsocket.c
示例12: rb_yaram_mbox_write_unblocked
/*
* call-seq:
* #write_unblocked(string) -> integer
*
* Writes the given string to <em>ios</em> using
* the write(2) system call. It assumes that O_NONBLOCK
* is already set for the underlying file descriptor.
*
* Over ~100,000 calls it is about 0.043 seconds faster.
*
* It returns the number of bytes written.
*/
static VALUE
rb_yaram_mbox_write_unblocked(VALUE self, VALUE io, VALUE str)
{
rb_io_t *fptr;
long n;
rb_secure(4);
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
io = rb_io_get_write_io(io);
GetOpenFile(io, fptr);
rb_io_check_writable(fptr);
if (io_fflush(fptr) < 0)
rb_sys_fail(0);
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
if (n == -1) {
if (errno == EWOULDBLOCK || errno == EAGAIN)
rb_mod_sys_fail(rb_mWaitWritable, "write would block");
rb_sys_fail_path(fptr->pathv);
}
return LONG2FIX(n);
}
开发者ID:simulacre,项目名称:Yaram,代码行数:39,代码来源:yaramc.c
示例13: ossl_obj2bio
BIO *
ossl_obj2bio(VALUE obj)
{
BIO *bio;
if (RB_TYPE_P(obj, T_FILE)) {
rb_io_t *fptr;
FILE *fp;
int fd;
GetOpenFile(obj, fptr);
rb_io_check_readable(fptr);
if ((fd = rb_cloexec_dup(FPTR_TO_FD(fptr))) < 0){
rb_sys_fail(0);
}
rb_update_max_fd(fd);
if (!(fp = fdopen(fd, "r"))){
int e = errno;
close(fd);
rb_syserr_fail(e, 0);
}
if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){
fclose(fp);
ossl_raise(eOSSLError, NULL);
}
}
else {
StringValue(obj);
bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
if (!bio) ossl_raise(eOSSLError, NULL);
}
return bio;
}
开发者ID:gferguson-gd,项目名称:ruby,代码行数:34,代码来源:ossl_bio.c
示例14: rsock_bsock_send
/*
* call-seq:
* basicsocket.send(mesg, flags [, dest_sockaddr]) => numbytes_sent
*
* send _mesg_ via _basicsocket_.
*
* _mesg_ should be a string.
*
* _flags_ should be a bitwise OR of Socket::MSG_* constants.
*
* _dest_sockaddr_ should be a packed sockaddr string or an addrinfo.
*
* TCPSocket.open("localhost", 80) {|s|
* s.send "GET / HTTP/1.0\r\n\r\n", 0
* p s.read
* }
*/
VALUE
rsock_bsock_send(int argc, VALUE *argv, VALUE sock)
{
struct rsock_send_arg arg;
VALUE flags, to;
rb_io_t *fptr;
int n;
rb_blocking_function_t *func;
rb_secure(4);
rb_scan_args(argc, argv, "21", &arg.mesg, &flags, &to);
StringValue(arg.mesg);
if (!NIL_P(to)) {
SockAddrStringValue(to);
to = rb_str_new4(to);
arg.to = (struct sockaddr *)RSTRING_PTR(to);
arg.tolen = (socklen_t)RSTRING_LENINT(to);
func = rsock_sendto_blocking;
}
else {
func = rsock_send_blocking;
}
GetOpenFile(sock, fptr);
arg.fd = fptr->fd;
arg.flags = NUM2INT(flags);
while (rb_thread_fd_writable(arg.fd),
(n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
if (rb_io_wait_writable(arg.fd)) {
continue;
}
rb_sys_fail("send(2)");
}
return INT2FIX(n);
}
开发者ID:AeonSaber,项目名称:first_app,代码行数:52,代码来源:basicsocket.c
示例15: control_block_open
static VALUE
control_block_open(int argc, VALUE *argv, VALUE cb)
{
const char *fmode;
#ifdef RUBY19
rb_io_t *fptr;
#else
OpenFile *fptr;
#endif
VALUE file, mode;
rb_aiocb_t *cbs = GetCBStruct(cb);
rb_scan_args(argc, argv, "02", &file, &mode);
fmode = NIL_P(mode) ? "r" : RSTRING_PTR(mode);
struct stat stats;
Check_Type(file, T_STRING);
cbs->io = rb_file_open(RSTRING_PTR(file), fmode);
GetOpenFile(cbs->io, fptr);
rb_io_check_readable(fptr);
if ( cbs->cb.aio_fildes == 0 && cbs->cb.aio_nbytes == 0){
#ifdef RUBY19
cbs->cb.aio_fildes = fptr->fd;
#else
cbs->cb.aio_fildes = fileno(fptr->f);
#endif
fstat(cbs->cb.aio_fildes, &stats);
control_block_nbytes_set(cb, INT2FIX(stats.st_size));
}
return cb;
}
开发者ID:methodmissing,项目名称:aio,代码行数:32,代码来源:aio.c
示例16: bsock_do_not_reverse_lookup
/*
* call-seq:
* basicsocket.do_not_reverse_lookup => true or false
*
* Gets the do_not_reverse_lookup flag of _basicsocket_.
*
* TCPSocket.open("www.ruby-lang.org", 80) {|sock|
* p sock.do_not_reverse_lookup #=> false
* p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"]
* sock.do_not_reverse_lookup = true
* p sock.peeraddr #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"]
* }
*/
static VALUE
bsock_do_not_reverse_lookup(VALUE sock)
{
rb_io_t *fptr;
GetOpenFile(sock, fptr);
return (fptr->mode & FMODE_NOREVLOOKUP) ? Qtrue : Qfalse;
}
开发者ID:AeonSaber,项目名称:first_app,代码行数:21,代码来源:basicsocket.c
示例17: binyo_instream_new_fd_io
binyo_instream *
binyo_instream_new_fd_io(VALUE value)
{
rb_io_t *fptr;
GetOpenFile(value, fptr);
rb_io_check_byte_readable(fptr);
return binyo_instream_new_fd(fptr->fd);
}
开发者ID:LarsWestergren,项目名称:binyo,代码行数:8,代码来源:io_in_fd.c
示例18: rb_io_nonblock_set
/*
* call-seq:
* io.nonblock = boolean -> boolean
*
* Enables non-blocking mode on a stream when set to
* +true+, and blocking mode when set to +false+.
*/
static VALUE
rb_io_nonblock_set(VALUE io, VALUE nb)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb));
return io;
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:15,代码来源:nonblock.c
示例19: ossl_ssl_read_internal
static VALUE
ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
{
SSL *ssl;
int ilen, nread = 0;
VALUE len, str;
rb_io_t *fptr;
rb_scan_args(argc, argv, "11", &len, &str);
ilen = NUM2INT(len);
if(NIL_P(str)) str = rb_str_new(0, ilen);
else{
StringValue(str);
rb_str_modify(str);
rb_str_resize(str, ilen);
}
if(ilen == 0) return str;
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
if (ssl) {
if(!nonblock && SSL_pending(ssl) <= 0)
rb_thread_wait_fd(FPTR_TO_FD(fptr));
for (;;){
nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
switch(ssl_get_error(ssl, nread)){
case SSL_ERROR_NONE:
goto end;
case SSL_ERROR_ZERO_RETURN:
rb_eof_error();
case SSL_ERROR_WANT_WRITE:
write_would_block(nonblock);
rb_io_wait_writable(FPTR_TO_FD(fptr));
continue;
case SSL_ERROR_WANT_READ:
read_would_block(nonblock);
rb_io_wait_readable(FPTR_TO_FD(fptr));
continue;
case SSL_ERROR_SYSCALL:
if(ERR_peek_error() == 0 && nread == 0) rb_eof_error();
rb_sys_fail(0);
default:
ossl_raise(eSSLError, "SSL_read:");
}
}
}
else {
ID meth = nonblock ? rb_intern("read_nonblock") : rb_intern("sysread");
rb_warning("SSL session is not started yet.");
return rb_funcall(ossl_ssl_get_io(self), meth, 2, len, str);
}
end:
rb_str_set_len(str, nread);
OBJ_TAINT(str);
return str;
}
开发者ID:2220142,项目名称:ruby,代码行数:58,代码来源:ossl_ssl.c
示例20: rsock_init_unixsock
VALUE
rsock_init_unixsock(VALUE sock, VALUE path, int server)
{
struct sockaddr_un sockaddr;
socklen_t sockaddrlen;
int fd, status;
rb_io_t *fptr;
SafeStringValue(path);
fd = rsock_socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
rsock_sys_fail_path("socket(2)", path);
}
INIT_SOCKADDR_UN(&sockaddr, sizeof(struct sockaddr_un));
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
rb_raise(rb_eArgError, "too long unix socket path (%ldbytes given but %dbytes max)",
RSTRING_LEN(path), (int)sizeof(sockaddr.sun_path));
}
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
sockaddrlen = rsock_unix_sockaddr_len(path);
if (server) {
status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
}
else {
int prot;
struct unixsock_arg arg;
arg.sockaddr = &sockaddr;
arg.sockaddrlen = sockaddrlen;
arg.fd = fd;
status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
if (prot) {
close(fd);
rb_jump_tag(prot);
}
}
if (status < 0) {
close(fd);
rsock_sys_fail_path("connect(2)", path);
}
if (server) {
if (listen(fd, SOMAXCONN) < 0) {
close(fd);
rsock_sys_fail_path("listen(2)", path);
}
}
rsock_init_sock(sock, fd);
if (server) {
GetOpenFile(sock, fptr);
fptr->pathv = rb_str_new_frozen(path);
}
return sock;
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:58,代码来源:unixsocket.c
注:本文中的GetOpenFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论