00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef RDMA_FACTORIES_H
00022 #define RDMA_FACTORIES_H
00023
00024 #include "rdma_exception.h"
00025
00026 #include <rdma/rdma_cma.h>
00027
00028 #include <boost/shared_ptr.hpp>
00029
00030 namespace Rdma {
00031
00032 void acker(::rdma_cm_event* e) throw ();
00033 void destroyEChannel(::rdma_event_channel* c) throw ();
00034 void destroyId(::rdma_cm_id* i) throw ();
00035 void deallocPd(::ibv_pd* p) throw ();
00036 void destroyCChannel(::ibv_comp_channel* c) throw ();
00037 void destroyCq(::ibv_cq* cq) throw ();
00038
00039 inline boost::shared_ptr< ::rdma_event_channel > mkEChannel() {
00040 return
00041 boost::shared_ptr< ::rdma_event_channel >(::rdma_create_event_channel(), destroyEChannel);
00042 }
00043
00044 inline boost::shared_ptr< ::rdma_cm_id >
00045 mkId(::rdma_event_channel* ec, void* context, ::rdma_port_space ps) {
00046 ::rdma_cm_id* i;
00047 CHECK(::rdma_create_id(ec, &i, context, ps));
00048 return boost::shared_ptr< ::rdma_cm_id >(i, destroyId);
00049 }
00050
00051 inline boost::shared_ptr< ::ibv_pd > allocPd(::ibv_context* c) {
00052 ::ibv_pd* pd = CHECK_NULL(ibv_alloc_pd(c));
00053 return boost::shared_ptr< ::ibv_pd >(pd, deallocPd);
00054 }
00055
00056 inline boost::shared_ptr< ::ibv_comp_channel > mkCChannel(::ibv_context* c) {
00057 ::ibv_comp_channel* cc = CHECK_NULL(::ibv_create_comp_channel(c));
00058 return boost::shared_ptr< ::ibv_comp_channel >(cc, destroyCChannel);
00059 }
00060
00061 inline boost::shared_ptr< ::ibv_cq >
00062 mkCq(::ibv_context* c, int cqe, void* context, ::ibv_comp_channel* cc) {
00063 ::ibv_cq* cq = CHECK_NULL(ibv_create_cq(c, cqe, context, cc, 0));
00064 return boost::shared_ptr< ::ibv_cq >(cq, destroyCq);
00065 }
00066 }
00067
00068 #endif // RDMA_FACTORIES_H