X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=low-can-binding%2Futils%2Fsocketcan.cpp;h=e8e01980789c005965084dfcffe520af6f96600f;hb=fe780799e8117ac30f9c05bcd43616638f35e66a;hp=b943d1d7200419309c25a399edfc10ac0e217cfa;hpb=8b8afeed2c93791b37b2451e00b73174e2d296c5;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/utils/socketcan.cpp b/low-can-binding/utils/socketcan.cpp index b943d1d7..e8e01980 100644 --- a/low-can-binding/utils/socketcan.cpp +++ b/low-can-binding/utils/socketcan.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2016 ,2017 "IoT.bzh" + * Copyright (C) 2015, 2016 , 2017, 2018, 2019 "IoT\.bzh" * Author "Romain Forlot" * Author "Loïc Collignon" * Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,6 +73,9 @@ namespace utils { close(); socket_ = ::socket(domain, type, protocol); + if (socket_ < 0) + AFB_ERROR("Open failed. %s", strerror(errno)); + return socket_; } @@ -96,4 +99,32 @@ namespace utils { return socket_; } + + /// @brief Connect the socket. + /// @return 0 if success. + int socketcan_t::connect(const struct sockaddr* addr, socklen_t len) + { + return socket_ != INVALID_SOCKET ? ::connect(socket_, addr, len) : 0; + } + + /// @brief Bind the socket. + /// @return 0 if success. + int socketcan_t::bind(const struct sockaddr* addr, socklen_t len) + { + return socket_ != INVALID_SOCKET ? ::bind(socket_, addr, len) : 0; + } + + int socketcan_t::write_message(std::vector& vobj) + { + for(int i=0;i