00001 /* 00002 * Scale Stack 00003 * 00004 * Copyright 2010 Eric Day 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00024 #include "config.h" 00025 00026 #include <scalestack/echo/server/stream.h> 00027 00028 namespace scalestack 00029 { 00030 namespace echo 00031 { 00032 namespace server 00033 { 00034 00035 /* 00036 * Public methods. 00037 */ 00038 00039 stream::stream(kernel::module& module): 00040 network::stream(module), 00041 _size(), 00042 _buffer() 00043 { 00044 } 00045 00046 size_t stream::read(uint8_t* buffer, size_t size) 00047 { 00048 _size = size; 00049 _buffer = buffer; 00050 return _echo(); 00051 } 00052 00053 void stream::flush_write(void) 00054 { 00055 consume(_echo()); 00056 } 00057 00058 /* 00059 * Private methods. 00060 */ 00061 00062 size_t stream::_echo(void) 00063 { 00064 size_t written = write(_buffer, _size, true); 00065 _size -= written; 00066 _buffer += written; 00067 return written; 00068 } 00069 00070 } /* namespace server */ 00071 } /* namespace echo */ 00072 } /* namespace scalestack */
1.6.3