Permalink
Browse files

Inherited Client from Stream instead of Print

Added Client.peek function for this.
  • Loading branch information...
jcrouchley committed Dec 9, 2011
1 parent 10c4c33 commit cbca8afe220aa57c30a05a940fabbea8ff9c67c8
Showing with 24 additions and 2 deletions.
  1. +6 −0 src/WiFly/Client.cpp
  2. +3 −2 src/WiFly/Client.h
  3. +14 −0 src/WiFly/ParsedStream.cpp
  4. +1 −0 src/WiFly/ParsedStream.h
View
@@ -131,6 +131,12 @@ int Client::read() {
return stream.read();
}
+int Client::peek() {
+ if (!isOpen) {
+ return -1;
+ }
+ return stream.peek();
+}
void Client::flush(void) {
/*
View
@@ -4,14 +4,14 @@
#ifndef __WIFLY_CLIENT_H__
#define __WIFLY_CLIENT_H__
-#include "Print.h"
+#include "Stream.h"
#include "ParsedStream.h"
#include "WiFlyDevice.h"
// TODO: Call this 'WiFlyClient' instead?
-class Client : public Print {
+class Client : public Stream {
public:
Client(uint8_t *ip, uint16_t port);
Client(const char* domain, uint16_t port);
@@ -25,6 +25,7 @@ class Client : public Print {
int available();
int read();
void flush(void);
+ int peek();
bool connected();
void stop();
View
@@ -87,6 +87,20 @@ int ParsedStream::read(void) {
}
}
+int ParsedStream::peek(void) {
+
+ if (!available()) {
+ getByte();
+ }
+
+ if (!available()) {
+ return -1;
+ } else {
+ unsigned char c = _rx_buffer.buffer[_rx_buffer.tail];
+ return c;
+ }
+}
+
int ParsedStream::freeSpace() {
View
@@ -43,6 +43,7 @@ class ParsedStream {
void begin(Stream* theUart);
uint8_t available(void);
int read(void);
+ int peek(void);
bool closed();

0 comments on commit cbca8af

Please sign in to comment.