Comments (7)
I'm not sure where this is used, but it might be better to use the rb_wait_* functions too:
https://github.com/github/trilogy/blob/2dd91e5d1974b29473ad646e5dba0a50562fe37a/src/socket.c#L50
_cb_wait
is not used at all in the Ruby gem. That's the default for anyone using the C lib directly, but for Ruby we swap it out at https://github.com/github/trilogy/blob/2dd91e5d1974b29473ad646e5dba0a50562fe37a/contrib/ruby/ext/trilogy-ruby/cext.c#L251-L253 with a wait_cb using rb_wait_for_single_fd
.
That's about the extent of my knowledge at the moment. I'd happy to help make whatever changes are desirable here, but I'll probably need to learn a lot more about the fiber scheduler, the difference between rb_wait_for_single_fd and rb_io_wait, etc.
from trilogy.
I am happy to make a PR if you are willing to work with me getting it merged?
from trilogy.
Would be more efficient if we could use rb_io_wait
but this is a good start.
from trilogy.
I'm not sure where this is used, but it might be better to use the rb_wait_* functions too:
https://github.com/github/trilogy/blob/2dd91e5d1974b29473ad646e5dba0a50562fe37a/src/socket.c#L50
from trilogy.
I am happy to make a PR if you are willing to work with me getting it merged?
Yes, I can do that!
from trilogy.
I started playing around with the code.
static int _cb_ruby_wait(trilogy_sock_t *sock, trilogy_wait_t wait)
{
struct timeval *timeout = NULL;
int wait_flag = 0;
switch (wait) {
case TRILOGY_WAIT_READ:
timeout = &sock->opts.read_timeout;
wait_flag = RB_WAITFD_IN;
break;
case TRILOGY_WAIT_WRITE:
timeout = &sock->opts.write_timeout;
wait_flag = RB_WAITFD_OUT;
break;
case TRILOGY_WAIT_HANDSHAKE:
timeout = &sock->opts.connect_timeout;
wait_flag = RB_WAITFD_IN;
break;
default:
return TRILOGY_ERR;
}
if (timeout->tv_sec == 0 && timeout->tv_usec == 0) {
timeout = NULL;
}
int fd = trilogy_sock_fd(sock);
if (rb_wait_for_single_fd(fd, wait_flag, timeout) <= 0)
return TRILOGY_SYSERR;
return 0;
}
The rb_wait_for_single_fd
should be replaced with rb_io_wait(io, RB_INT2NUM(wait_flag), rb_fiber_scheduler_make_timeout(timeout))
.
The io
object can be created by using RB_IO_OPEN
but I'll need to check the exact syntax.
I think the callback argument will need to be added or the existing context should be changed to store the io
, e.g.
struct trilogy_ctx {
trilogy_conn_t conn;
VALUE io;
char server_version[TRILOGY_SERVER_VERSION_SIZE + 1];
unsigned int query_flags;
};
Do you have any thoughts about how to best achieve this? Maybe we can add a void *context
to struct trilogy_sock_t
which refers to trilogy_ctx
.
Also, just for your reference, naming conventions with trailing _t
is highly discouraged by POSIX standard. https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_12 - _t
suffix is reserved for system types.
from trilogy.
I've opened a draft PR with the above changes.
from trilogy.
Related Issues (20)
- Use memset_s() instead of memset() to clear passwords
- Prepared Statements: Ruby support HOT 5
- Improved Ruby error classes HOT 6
- Compile Ruby in parallel
- Trilogy::SSLError is raised when a vitess vtgate is shut down HOT 2
- Client returns TRILOGY_INVALID_SEQUENCE_ID HOT 1
- CI for old Rubies doesn't work correctly
- failed install on windows 11 with mysys64 HOT 1
- [Ruby] Potential compaction issue in `rb_trilogy_connect`? HOT 2
- Include field names when using `query`. HOT 9
- `Trilogy.connect` not working in Staging and Production environments. HOT 8
- How did you solve the connection "feature" that translates `localhost` to a local UNIX socket? HOT 1
- Support for cleartext password
- Connection Fails in GitHub Actions HOT 3
- `trilogy` can't connect to remote Rails db, but `mysql2` can with identical `database.yml` HOT 1
- A more native GitHub Actions workflow would be nice HOT 2
- Add configuration option for SSL_OP_IGNORE_UNEXPECTED_EOF? HOT 1
- [Ruby] Add a Pipelining API?
- Make C-extension Ractor-safe HOT 1
- Non-C extension support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trilogy.