|
@@ -12,7 +12,8 @@
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
-#include "util/events/libuv/UvWrapper.h"
|
|
|
+#include "rust/cjdns_sys/Rffi.h"
|
|
|
+// #include "util/events/libuv/UvWrapper.h"
|
|
|
#include "memory/Allocator.h"
|
|
|
#include "util/events/libuv/EventBase_pvt.h"
|
|
|
#include "util/events/Event.h"
|
|
@@ -21,64 +22,74 @@
|
|
|
#include <stddef.h>
|
|
|
#include <stdint.h>
|
|
|
|
|
|
-struct Event_pvt
|
|
|
-{
|
|
|
- struct Event pub;
|
|
|
- void (* const callback)(void* callbackContext);
|
|
|
- void* const callbackContext;
|
|
|
- uv_poll_t handler;
|
|
|
- struct Allocator* alloc;
|
|
|
- Identity
|
|
|
-};
|
|
|
+// struct Event_pvt
|
|
|
+// {
|
|
|
+// struct Event pub;
|
|
|
+// void (* const callback)(void* callbackContext);
|
|
|
+// void* const callbackContext;
|
|
|
+// uv_poll_t handler;
|
|
|
+// struct Allocator* alloc;
|
|
|
+// Identity
|
|
|
+// };
|
|
|
|
|
|
-static void handleEvent(uv_poll_t* handle, int status, int events)
|
|
|
-{
|
|
|
- struct Event_pvt* event =
|
|
|
- Identity_check((struct Event_pvt*) (((char*)handle) - offsetof(struct Event_pvt, handler)));
|
|
|
+// static void handleEvent(uv_poll_t* handle, int status, int events)
|
|
|
+// {
|
|
|
+// struct Event_pvt* event =
|
|
|
+// Identity_check((struct Event_pvt*) (((char*)handle) - offsetof(struct Event_pvt, handler)));
|
|
|
|
|
|
- if ((status == 0) && (events & UV_READABLE)) {
|
|
|
- event->callback(event->callbackContext);
|
|
|
- }
|
|
|
-}
|
|
|
+// if ((status == 0) && (events & UV_READABLE)) {
|
|
|
+// event->callback(event->callbackContext);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
-static void onClose(uv_handle_t* handle)
|
|
|
-{
|
|
|
- struct Event_pvt* event = Identity_check((struct Event_pvt*) handle->data);
|
|
|
- Allocator_free(event->alloc);
|
|
|
-}
|
|
|
+// static void onClose(uv_handle_t* handle)
|
|
|
+// {
|
|
|
+// struct Event_pvt* event = Identity_check((struct Event_pvt*) handle->data);
|
|
|
+// Allocator_free(event->alloc);
|
|
|
+// }
|
|
|
|
|
|
-static int onFree(struct Allocator_OnFreeJob* job)
|
|
|
-{
|
|
|
- struct Event_pvt* event = Identity_check((struct Event_pvt*) job->userData);
|
|
|
- event->handler.data = event;
|
|
|
- uv_close((uv_handle_t*) &event->handler, onClose);
|
|
|
- return 0;
|
|
|
-}
|
|
|
+// static int onFree(struct Allocator_OnFreeJob* job)
|
|
|
+// {
|
|
|
+// struct Event_pvt* event = Identity_check((struct Event_pvt*) job->userData);
|
|
|
+// event->handler.data = event;
|
|
|
+// uv_close((uv_handle_t*) &event->handler, onClose);
|
|
|
+// return 0;
|
|
|
+// }
|
|
|
|
|
|
-struct Event* Event_socketRead(void (* const callback)(void* callbackContext),
|
|
|
- void* const callbackContext,
|
|
|
- int s,
|
|
|
- struct EventBase* eventBase,
|
|
|
- struct Allocator* userAlloc)
|
|
|
+void Event_socketRead(void (* const callback)(void* callbackContext),
|
|
|
+ void* const callbackContext,
|
|
|
+ int s,
|
|
|
+ struct EventBase* eventBase,
|
|
|
+ struct Allocator* userAlloc)
|
|
|
{
|
|
|
struct EventBase_pvt* base = EventBase_privatize(eventBase);
|
|
|
- struct Allocator* alloc = Allocator_child(base->alloc);
|
|
|
- struct Event_pvt* out = Allocator_clone(alloc, (&(struct Event_pvt) {
|
|
|
- .callback = callback,
|
|
|
- .callbackContext = callbackContext,
|
|
|
- .alloc = alloc
|
|
|
- }));
|
|
|
- Identity_set(out);
|
|
|
+ Rffi_FdReadableTx* out = NULL;
|
|
|
+ Rffi_pollFdReadable(
|
|
|
+ &out,
|
|
|
+ callback,
|
|
|
+ callbackContext,
|
|
|
+ s,
|
|
|
+ base->rffi_loop,
|
|
|
+ userAlloc);
|
|
|
+
|
|
|
+ // struct EventBase_pvt* base = EventBase_privatize(eventBase);
|
|
|
+ // struct Allocator* alloc = Allocator_child(base->alloc);
|
|
|
+ // struct Event_pvt* out = Allocator_clone(alloc, (&(struct Event_pvt) {
|
|
|
+ // .callback = callback,
|
|
|
+ // .callbackContext = callbackContext,
|
|
|
+ // .alloc = alloc
|
|
|
+ // }));
|
|
|
+ // Identity_set(out);
|
|
|
|
|
|
- // != 0 check, removed because uv_poll_init always returns 0
|
|
|
- uv_poll_init(base->loop, &out->handler, s);
|
|
|
+ // // != 0 check, removed because uv_poll_init always returns 0
|
|
|
+ // uv_poll_init(base->loop, &out->handler, s);
|
|
|
|
|
|
- // == -1 check, removed because uv_poll_start always returns 0
|
|
|
- uv_poll_start(&out->handler, UV_READABLE, handleEvent);
|
|
|
+ // // == -1 check, removed because uv_poll_start always returns 0
|
|
|
+ // uv_poll_start(&out->handler, UV_READABLE, handleEvent);
|
|
|
|
|
|
- out->handler.data = out;
|
|
|
+ // out->handler.data = out;
|
|
|
|
|
|
- Allocator_onFree(userAlloc, onFree, out);
|
|
|
+ // Allocator_onFree(userAlloc, onFree, out);
|
|
|
|
|
|
- return &out->pub;
|
|
|
+ // return &out->pub;
|
|
|
}
|