Boost logo

Boost Users :

Subject: Re: [Boost-users] IOService and socket CAN under Linux
From: Andreas Wehrmann (a.wehrmann_at_[hidden])
Date: 2010-03-15 10:22:14


I'm afraid this didn't work, but I simply copied the header icmp.hpp and
made the proper modification which work :-)

/// Encapsulates the flags needed for socket CAN.
/**
  * The can class contains flags necessary for CAN sockets.
  */
class Can {
     public:
         /// The type of a CAN endpoint.
         typedef boost::asio::ip::basic_endpoint<Can> endpoint;

         /// The type of a resolver query.
         typedef boost::asio::ip::basic_resolver_query<Can> resolver_query;

         /// The type of a resolver iterator.
         typedef boost::asio::ip::basic_resolver_iterator<Can>
resolver_iterator;

         /// Construct to represent the socket CAN protocol.
         Can()
             : protocol_( CAN_RAW )
             , family_( PF_CAN )
         {
         }

         static Can v4()
         {
             return Can();
         }

         static Can v6()
         {
             return Can();
         }

         /// Obtain an identifier for the type of the protocol.
         int type() const
         {
             return SOCK_RAW;
         }

         /// Obtain an identifier for the protocol.
         int protocol() const
         {
             return protocol_;
         }

         /// Obtain an identifier for the protocol family.
         int family() const
         {
             return family_;
         }

         /// The CAN socket type.
         typedef boost::asio::basic_raw_socket<Can> socket;

         /// The CAN resolver type.
         typedef boost::asio::ip::basic_resolver<Can> resolver;

         /// Compare two protocols for equality.
         friend bool operator==(const Can& p1, const Can& p2)
         {
             return p1.protocol_ == p2.protocol_ && p1.family_ ==
p2.family_;
         }

         /// Compare two protocols for inequality.
         friend bool operator!=(const Can& p1, const Can& p2)
         {
             return p1.protocol_ != p2.protocol_ || p1.family_ !=
p2.family_;
         }

     private:
         int protocol_;
         int family_;
};

That way I can create a Socket object simply by writing
Can::socket mySkt( ios );
However you have to call open() manually for this one.

Best regards,
Andreas

On 03/10/2010 07:12 PM, Igor R wrote:
>> I'm currently working with socket CAN under Linux 2.6.25 and was wondering
>> how I can use these with the very handy boost ioservice facility.
>> Socket CAN is simply a raw socket created like this: socket(PF_CAN,
>> SOCK_RAW, CAN_RAW);
>>
>> Does someone maybe already have a socket CAN implementation for Boost?
>> Is there a way I can add a socket descriptor to an IOService and get a
>> callback when
>> the socket becomes readable, so that I can read data from the socket?
>> The peculiarity about raw CAN sockets is,
>> that when they become readable, you don't read the payload
>> of the received CAN frame(s) but a struct that represents the received CAN
>> frame.
>> So it behaves like a datagram socket: You only read full frames.
>> What I actually need is a notification mechanism using the IOService facility.
>>
> Maybe you can create the socket manually and then assign its
> descriptor to udp::socket?
> http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/basic_datagram_socket/assign.html
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Dipl.-Ing. (FH) Andreas Wehrmann
Software Development
--------------------------------------------------------------
Center Communication Systems GmbH
A-1210 Wien, Ignaz-Köck-Straße 19
Sitz in Wien
FN 796 88p, Firmenbuchgericht Wien
www.centersystems.com
Tel.: +43 (0) 190 199 - 3616
Mobile: +43 (0) 664 884 75916
Fax: +43 (0) 190 199 - 2110
E-Mail: a.wehrmann_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net