*/
SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf,
switch_size_t *len);
+
+SWITCH_DECLARE(switch_status_t) switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len);
/**
* @param from The apr_sockaddr_t to fill in the recipient info
*/
SWITCH_DECLARE(switch_size_t) switch_buffer_peek(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen);
+SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(_In_ switch_buffer_t *buffer, _Out_ const void **ptr);
+
/*! \brief Read data endlessly from a switch_buffer_t
* \param buffer any buffer of type switch_buffer_t
* \param data pointer to the read data to be returned
\note the string key must be a constant or a dynamic string
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data,
- _In_ switch_mutex_t *mutex);
+ _In_opt_ switch_mutex_t *mutex);
+/*!
+ \brief Retrieve data from a given hash
+ \param hash the hash to retrieve from
+ \param key the key to retrieve
+ \param mutex optional rwlock to wrlock
+ \return a pointer to the data held in the key
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock);
/*!
\brief Delete data from a hash based on desired key
\param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is deleted
*/
-SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex);
+
+/*!
+ \brief Delete data from a hash based on desired key
+ \param hash the hash to delete from
+ \param key the key from which to delete the data
+ \param mutex optional rwlock to wrlock
+ \return SWITCH_STATUS_SUCCESS if the data is deleted
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock);
/*!
\brief Delete data from a hash based on callback function
*/
SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
+/*!
+ \brief Retrieve data from a given hash
+ \param hash the hash to retrieve from
+ \param key the key to retrieve
+ \param mutex optional rwlock to rdlock
+ \return a pointer to the data held in the key
+*/
+SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock);
+
/*!
\brief Gets the first element of a hashtable
\param depricate_me [deprecated] NULL
return reading;
}
+SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(switch_buffer_t *buffer, const void **ptr)
+{
+ switch_size_t reading = 0;
+
+ if (buffer->used < 1) {
+ buffer->used = 0;
+ return 0;
+ } else {
+ reading = buffer->used;
+ }
+
+ *ptr = buffer->head;
+
+ return reading;
+}
+
SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
{
switch_size_t freespace, actual_freespace;
return SWITCH_STATUS_SUCCESS;
}
+SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock)
+{
+ if (rwlock) {
+ switch_thread_rwlock_wrlock(rwlock);
+ }
+
+ sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, (void *) data);
+
+ if (rwlock) {
+ switch_thread_rwlock_unlock(rwlock);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key)
{
sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
return SWITCH_STATUS_SUCCESS;
}
+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
+{
+ if (rwlock) {
+ switch_thread_rwlock_wrlock(rwlock);
+ }
+
+ sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
+
+ if (rwlock) {
+ switch_thread_rwlock_unlock(rwlock);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) {
switch_hash_index_t *hi = NULL;
return val;
}
+SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock)
+{
+ void *val;
+
+ if (rwlock) {
+ switch_thread_rwlock_rdlock(rwlock);
+ }
+
+ val = sqlite3HashFind(&hash->table, key, (int) strlen(key) + 1);
+
+ if (rwlock) {
+ switch_thread_rwlock_unlock(rwlock);
+ }
+
+ return val;
+}
+
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(char *depricate_me, switch_hash_t *hash)
{
return (switch_hash_index_t *) sqliteHashFirst(&hash->table);