Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
windoze committed Aug 31, 2015
1 parent 3d57743 commit dc4c2bf
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions include/fibio/http/common/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef fibio_http_common_websocket_hpp
#define fibio_http_common_websocket_hpp

#include <array>
#include <cstdint>
#include <iostream>

Expand Down Expand Up @@ -225,41 +226,64 @@ namespace fibio { namespace http { namespace websocket {
first=false;
}
}

template<typename Container>
void send(OPCODE op, const Container &c) {
send(op, std::begin(c), std::end(c));
}

template<typename RandomIterator>
void send_binary(RandomIterator begin, RandomIterator end) {
send(OPCODE::BINARY, begin, end);
}

template<typename Container>
void send_binary(const Container &c) {
send_binary(std::begin(c), std::end(c));
}

template<typename RandomIterator>
void send_text(RandomIterator begin, RandomIterator end) {
send(OPCODE::TEXT, begin, end);
}

template<typename CharT, typename Traits, typename Allocator>
void send_text(const std::basic_string<CharT, Traits, Allocator> &s) {
static_assert(sizeof(CharT)==1, "Text message cannot contain wide char");
send_text(s.cbegin(), s.cend());
template<typename Container>
void send_text(const Container &c) {
send_text(std::begin(c), std::end(c));
}

template<typename RandomIterator>
void ping(RandomIterator begin, RandomIterator end) {
send(OPCODE::PING, begin, end);
}

template<typename Container>
void ping(const Container &c) {
ping(std::begin(c), std::end(c));
}

template<typename RandomIterator>
void pong(RandomIterator begin, RandomIterator end) {
send(OPCODE::PONG, begin, end);
}

template<typename Container>
void pong(const Container &c) {
pong(std::begin(c), std::end(c));
}

template<typename RandomIterator>
void close(RandomIterator begin, RandomIterator end) {
send(OPCODE::CLOSE, begin, end);
}

template<typename Container>
void close(const Container &c) {
close(std::begin(c), std::end(c));
}

void close() {
std::string s;
close(s.begin(), s.end());
close(std::string());
}

template<typename OutputIterator>
Expand Down Expand Up @@ -353,4 +377,4 @@ namespace fibio { namespace http { namespace websocket {
typedef std::function<void(websocket::connection &)> connection_handler;
}}} // End of namespace fibio::http::websocket

#endif // !defined(fibio_http_common_websocket_hpp)
#endif // !defined(fibio_http_common_websocket_hpp)

0 comments on commit dc4c2bf

Please sign in to comment.