github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/3rd_party/fflib/include/ff/net/network/events.h (about)

     1  /***********************************************
     2  The MIT License (MIT)
     3  
     4  Copyright (c) 2012 Athrun Arthur <athrunarthur@gmail.com>
     5  
     6  Permission is hereby granted, free of charge, to any person obtaining a copy
     7  of this software and associated documentation files (the "Software"), to deal
     8  in the Software without restriction, including without limitation the rights
     9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10  copies of the Software, and to permit persons to whom the Software is
    11  furnished to do so, subject to the following conditions:
    12  
    13  The above copyright notice and this permission notice shall be included in
    14  all copies or substantial portions of the Software.
    15  
    16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    22  THE SOFTWARE.
    23  *************************************************/
    24  #pragma once
    25  
    26  #include "ff/net/common/common.h"
    27  #include "ff/net/network/tcp_client.h"
    28  #include "ff/net/network/tcp_connection_base.h"
    29  #include "ff/net/network/tcp_server.h"
    30  #include "ff/net/network/udp_point.h"
    31  
    32  namespace ff {
    33  namespace net {
    34  namespace event {
    35  struct tcp_get_connection {
    36    const static size_t identifier = 1;
    37    typedef std::function<void(tcp_connection_base *)> Handler_t;
    38  };
    39  // end tcp_get_connection
    40  struct tcp_lost_connection {
    41    const static size_t identifier = 2;
    42    typedef std::function<void(tcp_connection_base *)> Handler_t;
    43  }; // end tcp_get_connection
    44  
    45  //! This happens because the socked is invalid due to lost connection or errors
    46  struct tcp_pkg_send_failed {
    47    const static size_t identifier = 3;
    48    typedef ff::net::package_ptr package_ptr;
    49    typedef std::function<void(tcp_connection_base *, package_ptr)> Handler_t;
    50  };
    51  
    52  struct udp_send_recv_exception {
    53    const static size_t identifier = 4;
    54    // TODO, what's the event_handler we need?
    55  }; // end udp_send_recv_exception
    56  
    57  namespace more {
    58  struct tcp_server_start_listen {
    59    const static size_t identifier = 5;
    60    typedef std::function<void(tcp_endpoint)> Handler_t;
    61  }; // end struct tcp_server_start_listen
    62  
    63  struct tcp_server_accept_connection {
    64    const static size_t identifier = 6;
    65    typedef std::function<void(ff::net::tcp_connection_base_ptr)> Handler_t;
    66  };
    67  // end struct tcp_server_accept_connection
    68  struct tcp_server_accept_error {
    69    const static size_t identifier = 7;
    70    typedef boost::system::error_code error_code;
    71    typedef std::function<void(tcp_endpoint, error_code)> Handler_t;
    72  };
    73  // end tcp_server_accept_error
    74  struct tcp_start_recv_stream {
    75    const static size_t identifier = 8;
    76    typedef std::function<void(tcp_endpoint, tcp_endpoint)> Handler_t;
    77  };
    78  // end tcp_start_recv_stream
    79  struct tcp_start_send_stream {
    80    const static size_t identifier = 9;
    81    typedef std::function<void(ff::net::tcp_connection_base *, const char *,
    82                               size_t)>
    83        Handler_t;
    84  };
    85  // end tcp_start_send_stream
    86  struct tcp_client_start_connection {
    87    const static size_t identifier = 10;
    88    typedef std::function<void(tcp_endpoint)> Handler_t;
    89  };
    90  // end tcp_client_start_connection
    91  struct tcp_client_get_connection_succ {
    92    const static size_t identifier = 11;
    93    typedef std::function<void(ff::net::tcp_connection_base *)> Handler_t;
    94  };
    95  // end tcp_client_get_connection
    96  struct tcp_client_conn_error {
    97    const static size_t identifier = 12;
    98    typedef boost::system::error_code error_code;
    99    typedef std::function<void(ff::net::tcp_connection_base *, error_code)>
   100        Handler_t;
   101  };
   102  // end tcp_client_conn_error
   103  struct tcp_send_stream_succ {
   104    const static size_t identifier = 13;
   105    typedef std::function<void(ff::net::tcp_connection_base *, size_t)> Handler_t;
   106  };
   107  // end
   108  struct tcp_send_stream_error {
   109    const static size_t identifier = 14;
   110    typedef boost::system::error_code error_code;
   111    typedef std::function<void(ff::net::tcp_connection_base *, error_code)>
   112        Handler_t;
   113  };
   114  // end connect_sent_stream_error
   115  struct tcp_recv_stream_succ {
   116    const static size_t identifier = 15;
   117    typedef std::function<void(ff::net::tcp_connection_base *, size_t)> Handler_t;
   118  };
   119  // end connect_recv_stream_succ
   120  struct tcp_recv_stream_error {
   121    const static size_t identifier = 16;
   122    typedef boost::system::error_code error_code;
   123    typedef std::function<void(ff::net::tcp_connection_base *, error_code)>
   124        Handler_t;
   125  }; // end connect_recv_stream_error
   126  
   127  struct udp_send_data_succ {
   128    const static size_t identifier = 17;
   129    typedef std::function<void(udp_point *, size_t)> Handler_t;
   130  };
   131  struct udp_send_data_error {
   132    const static size_t identifier = 18;
   133    typedef boost::system::error_code error_code;
   134    typedef std::function<void(udp_point *, error_code)> Handler_t;
   135  };
   136  
   137  struct udp_recv_data_succ {
   138    const static size_t identifier = 19;
   139    typedef std::function<void(udp_point *, size_t)> Handler_t;
   140  };
   141  
   142  struct udp_recv_data_error {
   143    const static size_t identifier = 20;
   144    typedef std::function<void(udp_point *, boost::system::error_code)> Handler_t;
   145  };
   146  
   147  } // end namespace more
   148  } // namespace event
   149  
   150  } // namespace net
   151  } // namespace ff
   152