Giter VIP home page Giter VIP logo

Comments (3)

divanvisagie avatar divanvisagie commented on June 17, 2024

TODO: look into updating libuv dependency version

from node.native.

sebjameswml avatar sebjameswml commented on June 17, 2024

I've been looking at this. I think the error class gets simpler because there are fewer types to handle.

I've drafted out error.h as:

#ifndef __ERROR_H__
#define __ERROR_H__

#include "base.h"

namespace native
{
    class exception
    {
    public:
        exception(const std::string& message)
            : message_(message)
        {}

        virtual ~exception() {}

        const std::string& message() const { return message_; }

    private:
        std::string message_;
    };

    class error
    {
    public:
        error() : uv_err_(0) {}
        error(int e) : uv_err_(e) {}
        ~error() = default;

    public:
        operator bool() { return uv_err_ != 0; } // Is 0 the right number for no error in UV?

        int code() const { return uv_err_; }
        const char* name() const { return uv_err_name(uv_err_); }
        const char* str() const { return uv_strerror(uv_err_); }

    private:
        int uv_err_;
    };

    // uv no longer has uv_last_error. Instead use return from the uv call.
    //error get_last_error() { return uv_last_error(uv_default_loop()); }
}

#endif

But I don't know how to modify the calling code, such as tcp.h, fs.h and so on. Any hints from the original coder?

from node.native.

sebjameswml avatar sebjameswml commented on June 17, 2024

For example, here's a call to uv_tcp_connect from tcp.h:

 bool connect(const std::string& ip, int port, std::function<void(error)> callback)
            {
                callbacks::store(get()->data, native::internal::uv_cid_connect, callback);
                return uv_tcp_connect(new uv_connect_t, get<uv_tcp_t>(), to_ip4_addr(ip, port), [](uv_connect_t* req, int status) {
                    callbacks::invoke<decltype(callback)>(req->handle->data, native::internal::uv_cid_connect, status?uv_last_error(req->handle->loop):error());
                    delete req;
                }) == 0;
            }

Previously you had to call uv_last_error to get the last error code, if any. Now, uv_tcp_connect returns the error directly, as an int. So what about the handling of "status" in the callback? I can't see how to do the right thing here.

from node.native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.