# Path: config.py
# class API:
# 
#     LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
#     LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
#     LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
#     # ----------------------------------------- #
#     # ---- Socket API ---- #
#     LISTEN_PORT_SOCKET = chain_load_setting("API_SOCKET_PORT", "YAMS_API_SOCKET_PORT", default=1112)
# 
#     # Yield epsilon is to avoid busy-waiting.  0 denotes yielding to any ready thread.  See scheduler docs.
#     # I've found 0 to fully utilize a core, so defaults to a longer interval to save electricity.
#     YIELD_TO_READY_THREADS=0
#     SOCKET_THREAD_YIELD_EPSILON = 0.25
#     SOCKET_TIMEOUT_SECONDS = 30
#     SOCKET_RX_BUFFER_BYTES = 4096
# 
#     # ----------------------------------------- #
# 
#     DEBUG = chain_load_setting("DEBUG", "YAMS_API_DEBUG", True)
# 
#     API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
#     API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")
# 
#     default_datadir = os.path.join(basedir, "yams_api", "data")
#     DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)
# 
#     default_database = "sqlite:///" + os.path.join(basedir, "yams_api.sqlite")
#     SQLALCHEMY_DATABASE_URI = chain_load_setting("API_DATABASE_URI", "YAMS_API_DATABASE_URI", default=default_database)
# 
# 
#     # If we have redis, we have rate limiting available
#     try:
#         r = redis.Redis()
#         r.ping()
#         USE_RATE_LIMITS = True
#     except redis.ConnectionError:
#         USE_RATE_LIMITS = False
# 
# Path: yams_api/utils/logger.py
# class ContextFilter(logging.Filter):
# class Logger:
#     def filter(self, record):
#     def __init__(self, formatter=None, log_level=config.DEFAULT_LOG_LEVEL, syslog_address="/dev/log"):
#     def syslog(self):


import select
import socket
import socketserver
import sys
import _thread
import time
from config import API
from yams_api.utils.logger import log
from hashlib import md5
from ctypes import Structure
        this_bytes_rxd = this_bytes_rxd + len(current_chunk)

    return b''.join(byte_chunks)



# ----------------------------------------------------------------------------------------------- #

SOCKET_CONNECTIONS = []


# general metrics so we can expose how we're driving.
PROCESS_RX_BYTES = 0
PROCESS_TX_BYTES = 0


def make_server_socket():

    try:
        # Set up our socket and append it to our list of sockets we will be reading from

        # udp ip v4
        #sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # tcp ip v4
        sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        # reuse local address, 6 == tcp from /etc/protocols. see man 3 getprotoent
        sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 6)


# Path: config.py
# class API:
# 
#     LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
#     LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
#     LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
#     # ----------------------------------------- #
#     # ---- Socket API ---- #
#     LISTEN_PORT_SOCKET = chain_load_setting("API_SOCKET_PORT", "YAMS_API_SOCKET_PORT", default=1112)
# 
#     # Yield epsilon is to avoid busy-waiting.  0 denotes yielding to any ready thread.  See scheduler docs.
#     # I've found 0 to fully utilize a core, so defaults to a longer interval to save electricity.
#     YIELD_TO_READY_THREADS=0
#     SOCKET_THREAD_YIELD_EPSILON = 0.25
#     SOCKET_TIMEOUT_SECONDS = 30
#     SOCKET_RX_BUFFER_BYTES = 4096
# 
#     # ----------------------------------------- #
# 
#     DEBUG = chain_load_setting("DEBUG", "YAMS_API_DEBUG", True)
# 
#     API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
#     API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")
# 
#     default_datadir = os.path.join(basedir, "yams_api", "data")
#     DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)
# 
#     default_database = "sqlite:///" + os.path.join(basedir, "yams_api.sqlite")
#     SQLALCHEMY_DATABASE_URI = chain_load_setting("API_DATABASE_URI", "YAMS_API_DATABASE_URI", default=default_database)
# 
# 
#     # If we have redis, we have rate limiting available
#     try:
#         r = redis.Redis()
#         r.ping()
#         USE_RATE_LIMITS = True
#     except redis.ConnectionError:
#         USE_RATE_LIMITS = False
# 
# Path: yams_api/utils/logger.py
# class ContextFilter(logging.Filter):
# class Logger:
#     def filter(self, record):
#     def __init__(self, formatter=None, log_level=config.DEFAULT_LOG_LEVEL, syslog_address="/dev/log"):
#     def syslog(self):


# Path: yams_api/core/dev/transport/tcpsocket.py
import select
import socket
import socketserver
import sys
import _thread
import time
from config import API
from yams_api.utils.logger import log
from hashlib import md5
from ctypes import Structure

        this_bytes_rxd = this_bytes_rxd + len(current_chunk)

    return b''.join(byte_chunks)



# ----------------------------------------------------------------------------------------------- #

SOCKET_CONNECTIONS = []


# general metrics so we can expose how we're driving.
PROCESS_RX_BYTES = 0
PROCESS_TX_BYTES = 0


def make_server_socket():

    try:
        # Set up our socket and append it to our list of sockets we will be reading from

        # udp ip v4
        #sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # tcp ip v4
        sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        # reuse local address, 6 == tcp from /etc/protocols. see man 3 getprotoent
        sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 6)


        sock_tcp.bind((API.LISTEN_HOST, API.LISTEN_PORT_SOCKET))