Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created April 4, 2010 13:22
Show Gist options
  • Save Mon-Ouie/355395 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/355395 to your computer and use it in GitHub Desktop.
static VALUE
ossl_start_ssl(VALUE self, int (*func)())
{
SSL *ssl;
OpenFile *fptr;
int ret;
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
for(;;){
if((ret = func(ssl)) > 0) break;
switch(ssl_get_error(ssl, ret)){
case SSL_ERROR_WANT_WRITE:
rb_io_wait_writable(fileno(fptr->f));
continue;
case SSL_ERROR_WANT_READ:
rb_io_wait_readable(fileno(fptr->f));
continue;
case SSL_ERROR_SYSCALL:
if (errno) rb_sys_fail(0); /* an error occurs here */
default:
ossl_raise(eSSLError, NULL);
}
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment