001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024:
025:
026:
027:
028:
029:
030:
031:
032:
033:
034:
035:
036:
037:
038:
039:
040:
041:
042:
043:
044:
045:
046:
047:
048:
049:
050:
051:
052:
053:
054:
055:
056:
057:
058:
059:
060:
061:
062:
063:
064:
065:
066:
067:
068:
069:
070:
071:
072:
073:
074:
075:
076:
077:
078:
079:
080:
081:
082:
083:
084:
085:
086:
087:
088:
089:
090:
091:
092:
093:
094:
095:
096:
097:
098:
099:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
Min/Max

































































































































































































































































































































































































































































































































/*
* Copyright (c), Zeriph Enterprises
* All rights reserved.
*
* Contributor(s):
* Zechariah Perez, omni (at) zeriph (dot) com
*
* THIS SOFTWARE IS PROVIDED BY ZERIPH AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ZERIPH AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(OMNI_SOCKET_EP_HPP)
#define OMNI_SOCKET_EP_HPP 1
#include <omni/types/net_t.hpp>
#if defined(OMNI_SAFE_SOCKET_EP)
    #include <omni/sync/basic_lock.hpp>
#endif

#if defined(OMNI_32BIT_ENDPOINT_DESCRIPTOR)
    #define OMNI_EPDESC_INT_FW uint32_t
#else
    #define OMNI_EPDESC_INT_FW uint64_t
#endif

namespace omni {
    namespace net {
        class endpoint_descriptor
        {
            public:
                endpoint_descriptor();
                endpoint_descriptor(const omni::net::endpoint_descriptor& cp);
                ~endpoint_descriptor();
                
                omni::net::socket_error connect(const omni::net::socket_t& serv_sock);
                omni::net::socket_error close();
                omni::net::socket_error close(uint16_t timeout);
                uint32_t endpoint() const;
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t& op_val);
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, omni::net::socket_option op_name, int32_t& op_val);
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t& op_val);
                omni::net::socket_t native_handle() const;
                omni::net::socket_error ioc(uint32_t op_code, omni::net::xfr_t* val);
                bool is_ip4() const { return true; }
                bool is_ip6() const { return false; }
                bool is_connected() const;
                bool is_shutdown() const;
                omni::net::socket_error last_error() const;
                uint16_t port() const;

                template < typename T, uint16_t SZ >
                omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, uint32_t& received)
                {
                    return this->_receive(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, received);
                }
                template < typename T >
                omni::net::socket_error receive(std::vector<T>& buffer, uint32_t& received)
                {
                    // if CXX buffer.data
                    return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, received);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer.data(), buffer.memory_size(), flags, received);
                }
                template < typename T >
                omni::net::socket_error receive(std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& received)
                {
                    // if CXX buffer.data
                    return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), flags, received);
                }
                template < std::size_t SZ >
                omni::net::socket_error receive(char (&buffer)[SZ], uint32_t& received)
                {
                    return this->_receive(buffer, SZ, omni::net::socket_flags::NONE, received);
                }
                template < std::size_t SZ >
                omni::net::socket_error receive(char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer, SZ, flags, received);
                }
                omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, uint32_t& received)
                {
                    return this->_receive(buffer, buffer_size, omni::net::socket_flags::NONE, received);
                }
                omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer, buffer_size, flags, received);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, uint32_t& sent)
                {
                    return this->_send(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, sent);
                }
                template < typename T >
                omni::net::socket_error send(const std::vector<T>& buffer, uint32_t& sent)
                {
                    return this->_send(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, sent);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer.data(), buffer.memory_size(), flags, sent);
                }
                template < typename T >
                omni::net::socket_error send(const std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(&buffer[0], (buffer.size() * sizeof(T)), flags, sent);
                }
                template < std::size_t SZ >
                omni::net::socket_error send(const char (&buffer)[SZ], uint32_t& sent)
                {
                    return this->_send(buffer, SZ, omni::net::socket_flags::NONE, sent);
                }
                template < std::size_t SZ >
                omni::net::socket_error send(const char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer, SZ, flags, sent);
                }
                omni::net::socket_error send(const std::string& buffer, uint32_t& sent)
                {
                    return this->unsafe_send(buffer.data(), buffer.size(), sent);
                }
                omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, uint32_t& sent)
                {
                    return this->_send(buffer, buffer_size, omni::net::socket_flags::NONE, sent);
                }
                omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer, buffer_size, flags, sent);
                }
                
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t op_val);
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, omni::net::socket_option op_name, int32_t op_val);
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t op_val);
                omni::net::socket_error set_blocking_mode(omni::net::blocking_mode mode);
                omni::net::socket_error shutdown(omni::net::socket_shutdown how);
                void swap(omni::net::endpoint_descriptor& other);
                omni::string_t to_string_t() const;
                std::string to_string() const;
                std::wstring to_wstring() const;

                omni::net::endpoint_descriptor& operator=(omni::net::endpoint_descriptor& other);
                bool operator==(const omni::net::endpoint_descriptor& other) const;
                bool operator==(const omni::net::socket_t& sock) const;
                bool operator==(uint32_t ep) const;

                inline bool operator!=(const omni::net::endpoint_descriptor& other) const { return !(*this == other); }
                inline bool operator!=(const omni::net::socket_t& sock) const { return !(*this == sock); }
                inline bool operator!=(uint32_t ep) const { return !(*this == ep); }

                operator std::string() const
                {
                    return this->to_string();
                }

                operator std::wstring() const
                {
                    return this->to_wstring();
                }

                OMNI_MEMBERS_FW(omni::net::endpoint_descriptor) // disposing,name,type(),hash()

                OMNI_OSTREAM_FW(omni::net::endpoint_descriptor)

            private:
                omni::net::socket_t m_socket;
                omni::net::sockaddr_in_t m_addr;
                omni::net::socket_error m_last_err;
                volatile OMNI_EPDESC_INT_FW m_status;

                #if defined(OMNI_SAFE_SOCKET_EP)
                    mutable omni::sync::basic_lock m_mtx;
                #endif

                omni::net::socket_error _close(uint16_t timeout, bool shutdown);
                omni::net::socket_error _receive(void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& received);
                omni::net::socket_error _send(const void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent);
        };

        class endpoint_descriptor6
        {
            public:
                endpoint_descriptor6();
                endpoint_descriptor6(const omni::net::endpoint_descriptor6& cp);
                ~endpoint_descriptor6();
                
                omni::net::socket_error connect(const omni::net::socket_t& serv_sock);
                omni::net::socket_error close();
                omni::net::socket_error close(uint16_t timeout);
                std::string endpoint() const;
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t& op_val);
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, omni::net::socket_option op_name, int32_t& op_val);
                omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t& op_val);
                omni::net::socket_t native_handle() const;
                omni::net::socket_error ioc(uint32_t op_code, omni::net::xfr_t* val);
                bool is_ip4() const;
                bool is_ip6() const;
                bool is_connected() const;
                bool is_shutdown() const;
                omni::net::socket_error last_error() const;
                uint16_t port() const;

                template < typename T, uint16_t SZ >
                omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, uint32_t& received)
                {
                    return this->_receive(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, received);
                }
                template < typename T >
                omni::net::socket_error receive(std::vector<T>& buffer, uint32_t& received)
                {
                    // if CXX buffer.data
                    return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, received);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer.data(), buffer.memory_size(), flags, received);
                }
                template < typename T >
                omni::net::socket_error receive(std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& received)
                {
                    // if CXX buffer.data
                    return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), flags, received);
                }
                template < std::size_t SZ >
                omni::net::socket_error receive(char (&buffer)[SZ], uint32_t& received)
                {
                    return this->_receive(buffer, SZ, omni::net::socket_flags::NONE, received);
                }
                template < std::size_t SZ >
                omni::net::socket_error receive(char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer, SZ, flags, received);
                }
                omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, uint32_t& received)
                {
                    return this->_receive(buffer, buffer_size, omni::net::socket_flags::NONE, received);
                }
                omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, omni::net::socket_flags flags, uint32_t& received)
                {
                    return this->_receive(buffer, buffer_size, flags, received);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, uint32_t& sent)
                {
                    return this->_send(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, sent);
                }
                template < typename T >
                omni::net::socket_error send(const std::vector<T>& buffer, uint32_t& sent)
                {
                    return this->_send(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, sent);
                }
                template < typename T, uint16_t SZ >
                omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer.data(), buffer.memory_size(), flags, sent);
                }
                template < typename T >
                omni::net::socket_error send(const std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(&buffer[0], (buffer.size() * sizeof(T)), flags, sent);
                }
                template < std::size_t SZ >
                omni::net::socket_error send(const char (&buffer)[SZ], uint32_t& sent)
                {
                    return this->_send(buffer, SZ, omni::net::socket_flags::NONE, sent);
                }
                template < std::size_t SZ >
                omni::net::socket_error send(const char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer, SZ, flags, sent);
                }
                omni::net::socket_error send(const std::string& buffer, uint32_t& sent)
                {
                    return this->unsafe_send(buffer.data(), buffer.size(), sent);
                }
                omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, uint32_t& sent)
                {
                    return this->_send(buffer, buffer_size, omni::net::socket_flags::NONE, sent);
                }
                omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent)
                {
                    return this->_send(buffer, buffer_size, flags, sent);
                }
                
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t op_val);
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, omni::net::socket_option op_name, int32_t op_val);
                omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t op_val);
                omni::net::socket_error set_blocking_mode(omni::net::blocking_mode mode);
                omni::net::socket_error shutdown(omni::net::socket_shutdown how);
                void swap(omni::net::endpoint_descriptor6& other);
                omni::string_t to_string_t() const;
                std::string to_string() const;
                std::wstring to_wstring() const;

                omni::net::endpoint_descriptor6& operator=(omni::net::endpoint_descriptor6& other);
                bool operator==(const omni::net::endpoint_descriptor6& other) const;
                bool operator==(const omni::net::socket_t& sock) const;
                bool operator==(const std::string& ep) const;

                inline bool operator!=(const omni::net::endpoint_descriptor6& other) const { return !(*this == other); }
                inline bool operator!=(const omni::net::socket_t& sock) const { return !(*this == sock); }
                inline bool operator!=(const std::string& ep) const { return !(*this == ep); }

                operator std::string() const
                {
                    return this->to_string();
                }

                operator std::wstring() const
                {
                    return this->to_wstring();
                }

                OMNI_MEMBERS_FW(omni::net::endpoint_descriptor6) // disposing,name,type(),hash()

                OMNI_OSTREAM_FW(omni::net::endpoint_descriptor6)

            private:
                omni::net::socket_t m_socket;
                omni::net::sockaddr_in6_t m_addr;
                omni::net::socket_error m_last_err;
                volatile OMNI_EPDESC_INT_FW m_status;

                #if defined(OMNI_SAFE_SOCKET_EP6)
                    mutable omni::sync::basic_lock m_mtx;
                #endif

                omni::net::socket_error _close(uint16_t timeout, bool shutdown);
                omni::net::socket_error _receive(void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& received);
                omni::net::socket_error _send(const void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent);
        };
    }
    namespace ipc {
        #if defined(OMNI_ALLOW_UNIX_SOCKET)
            class unix_endpoint_descriptor
            {
                public:
                    unix_endpoint_descriptor();
                    unix_endpoint_descriptor(const omni::ipc::unix_endpoint_descriptor& cp);
                    ~unix_endpoint_descriptor();
                    
                    omni::net::socket_error connect(const omni::net::socket_t& serv_sock);
                    omni::net::socket_error close();
                    omni::net::socket_error close(uint16_t timeout);
                    std::string endpoint() const;
                    omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t& op_val);
                    omni::net::socket_error get_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t& op_val);
                    omni::net::socket_t native_handle() const;
                    omni::net::socket_error ioc(uint32_t op_code, omni::net::xfr_t* val);
                    bool is_connected() const;
                    bool is_shutdown() const;
                    omni::net::socket_error last_error() const;

                    template < typename T, uint16_t SZ >
                    omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, uint32_t& received)
                    {
                        return this->_receive(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, received);
                    }
                    template < typename T >
                    omni::net::socket_error receive(std::vector<T>& buffer, uint32_t& received)
                    {
                        // if CXX buffer.data
                        return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, received);
                    }
                    template < typename T, uint16_t SZ >
                    omni::net::socket_error receive(omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& received)
                    {
                        return this->_receive(buffer.data(), buffer.memory_size(), flags, received);
                    }
                    template < typename T >
                    omni::net::socket_error receive(std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& received)
                    {
                        // if CXX buffer.data
                        return this->_receive(&buffer[0], (buffer.size() * sizeof(T)), flags, received);
                    }
                    template < std::size_t SZ >
                    omni::net::socket_error receive(char (&buffer)[SZ], uint32_t& received)
                    {
                        return this->_receive(buffer, SZ, omni::net::socket_flags::NONE, received);
                    }
                    template < std::size_t SZ >
                    omni::net::socket_error receive(char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& received)
                    {
                        return this->_receive(buffer, SZ, flags, received);
                    }
                    omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, uint32_t& received)
                    {
                        return this->_receive(buffer, buffer_size, omni::net::socket_flags::NONE, received);
                    }
                    omni::net::socket_error unsafe_receive(char* buffer, uint32_t buffer_size, omni::net::socket_flags flags, uint32_t& received)
                    {
                        return this->_receive(buffer, buffer_size, flags, received);
                    }
                    template < typename T, uint16_t SZ >
                    omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, uint32_t& sent)
                    {
                        return this->_send(buffer.data(), buffer.memory_size(), omni::net::socket_flags::NONE, sent);
                    }
                    template < typename T >
                    omni::net::socket_error send(const std::vector<T>& buffer, uint32_t& sent)
                    {
                        return this->_send(&buffer[0], (buffer.size() * sizeof(T)), omni::net::socket_flags::NONE, sent);
                    }
                    template < typename T, uint16_t SZ >
                    omni::net::socket_error send(const omni::stack_buffer<T, SZ>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                    {
                        return this->_send(buffer.data(), buffer.memory_size(), flags, sent);
                    }
                    template < typename T >
                    omni::net::socket_error send(const std::vector<T>& buffer, omni::net::socket_flags flags, uint32_t& sent)
                    {
                        return this->_send(&buffer[0], (buffer.size() * sizeof(T)), flags, sent);
                    }
                    template < std::size_t SZ >
                    omni::net::socket_error send(const char (&buffer)[SZ], uint32_t& sent)
                    {
                        return this->_send(buffer, SZ, omni::net::socket_flags::NONE, sent);
                    }
                    template < std::size_t SZ >
                    omni::net::socket_error send(const char (&buffer)[SZ], omni::net::socket_flags flags, uint32_t& sent)
                    {
                        return this->_send(buffer, SZ, flags, sent);
                    }
                    omni::net::socket_error send(const std::string& buffer, uint32_t& sent)
                    {
                        return this->unsafe_send(buffer.data(), buffer.size(), sent);
                    }
                    omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, uint32_t& sent)
                    {
                        return this->_send(buffer, buffer_size, omni::net::socket_flags::NONE, sent);
                    }
                    omni::net::socket_error unsafe_send(const char* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent)
                    {
                        return this->_send(buffer, buffer_size, flags, sent);
                    }
                    
                    omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, int32_t op_name, int32_t op_val);
                    omni::net::socket_error set_socket_option(omni::net::socket_option_level op_level, omni::net::tcp_option op_name, int32_t op_val);
                    omni::net::socket_error set_blocking_mode(omni::net::blocking_mode mode);
                    omni::net::socket_error shutdown(omni::net::socket_shutdown how);
                    void swap(omni::ipc::unix_endpoint_descriptor& other);
                    omni::string_t to_string_t() const;
                    std::string to_string() const;
                    std::wstring to_wstring() const;

                    omni::ipc::unix_endpoint_descriptor& operator=(omni::ipc::unix_endpoint_descriptor& other);
                    bool operator==(const omni::ipc::unix_endpoint_descriptor& other) const;
                    bool operator==(const omni::net::socket_t& sock) const;
                    bool operator==(const std::string& ep) const;

                    inline bool operator!=(const omni::ipc::unix_endpoint_descriptor& other) const { return !(*this == other); }
                    inline bool operator!=(const omni::net::socket_t& sock) const { return !(*this == sock); }
                    inline bool operator!=(const std::string& ep) const { return !(*this == ep); }

                    operator std::string() const
                    {
                        return this->to_string();
                    }

                    operator std::wstring() const
                    {
                        return this->to_wstring();
                    }

                    OMNI_MEMBERS_FW(omni::ipc::unix_endpoint_descriptor) // disposing,name,type(),hash()

                    OMNI_OSTREAM_FW(omni::ipc::unix_endpoint_descriptor)

                private:
                    omni::net::socket_t m_socket;
                    omni::net::sockaddr_un_t m_addr;
                    omni::net::socket_error m_last_err;
                    volatile OMNI_EPDESC_INT_FW m_status;

                    #if defined(OMNI_SAFE_UNIX_SOCKET_EP)
                        mutable omni::sync::basic_lock m_mtx;
                    #endif

                    omni::net::socket_error _close(uint16_t timeout, bool shutdown);
                    omni::net::socket_error _receive(void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& received);
                    omni::net::socket_error _send(const void* buffer, std::size_t buffer_size, omni::net::socket_flags flags, uint32_t& sent);
            };
        #endif
    }
}

namespace std {
    inline void swap(omni::net::endpoint_descriptor& o1, omni::net::endpoint_descriptor& o2)
    {
        o1.swap(o2);
    }
    inline void swap(omni::net::endpoint_descriptor6& o1, omni::net::endpoint_descriptor6& o2)
    {
        o1.swap(o2);
    }
    #if defined(OMNI_ALLOW_UNIX_SOCKET)
        inline void swap(omni::ipc::unix_endpoint_descriptor& o1, omni::ipc::unix_endpoint_descriptor& o2)
        {
            o1.swap(o2);
        }
    #endif
}

#endif // OMNI_SOCKET_EP_HPP