Boost logo

Boost Users :

Subject: [Boost-users] [Asio] Need help making a custom service
From: Kyle Edwards (kedwards_at_[hidden])
Date: 2015-03-09 13:49:44

Hello everyone,

First off, I would like to say that I have been using Boost for the past
few years, and have found it very useful. Thanks for all your hard work!

Second, I have a question about making a custom service. I would like to
make a service that triggers a callback when a GPIO pin changes state
and triggers an interrupt (I'm using a Raspberry Pi.) I have (or can
obtain) a file descriptor that can be poll()'d, select()'d, or epoll'd
and which omits high-priority events (POLLPRI, EPOLLPRI, etc.). This
entire use case is pretty Linux-specific, so it doesn't have to be very
portable. What I would like to be able to do is something like this:


#include <iostream>
#include <boost/asio.hpp>

class gpio_interrupt {
  gpio_interrupt(boost::asio::io_service &io_service,
                 unsigned int number)
    // Asio magic goes here

  template <typename Callback>
  void async_wait(Callback c)
    // Asio magic goes here

static void my_callback(const boost::system::error_code &ec)
  if (ec)

  std::cout << "Pin changed state" << std::endl;

int main(int argc, char **argv)
  boost::asio::io_service io_service;
  gpio_interrupt interrupt(io_service, 21);

  return 0;


I've looked a little bit at the Boost.Asio code (in particular the
socket code) to get an idea of how I would do this, but there are so
many different classes and inner classes that I'm not sure where to get
started. Can someone help me? Thanks in advance!


Kyle Edwards

Software Developer

20 Corporate Circle | Albany, NY 12203

office 888-4BULLEX | 518.689.2023 | fax 518.689.2034 | web:

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at