Skip to content

to integrate new lib uv (new error checking mechannizm) #21

Open

Description

@shimondoodkin

I have tried to update the libuv and found out that just now there was a major change in libuv.

joyent/libuv@3ee4d3f

joyent/libuv#696

Activity

  1. divanvisagie commented on Aug 22, 2013

    @divanvisagie
    Collaborator

    TODO: look into updating libuv dependency version

  2. sebjameswml commented on Nov 7, 2013

    @sebjameswml
    Contributor

    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?

  3. sebjameswml commented on Nov 7, 2013

    @sebjameswml
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions